Skip to content

A2 - Simple CPU Emulator

Run update.bat (most of you will have this in your T: drive for this course). It will create a new subfolder called Assembly in your Local folder. In this folder will be two files:

  • asm.py - This is an emulator, written in Python, for the simple cpu language that was introduced in yesterday's handout. An emulator is a simulator for a CPU. You will never need to touch anything in this file.
  • example.asm - This is an example of an assembly language file that can be run by the emulator.

Open example.asm. You should recognize the instructions in here from yesterday's handout. You will also note that comments can be added using the same notation as Python. Assembly language is notoriously difficult to follow, so adding comments is super important!

To run the emulator, you need to open a terminal. You can do this by going to the Terminal menu in Visual Studio Code and selecting the first option, New Terminal. Alternatively, you can use the keyboard shortcut CTRL+` (the key to the left of the number 1).

Once the terminal opens, type the following command into the terminal:

py asm.py example.asm
This will run your program using the emulator. Note, that if you want to rerun a terminal command, you can press the up arrow on the keyboard to go through command history.

Your Task

Write three of your own assembly language programs that solve mathematical expressions. See how complex you can make them (within reason)!

You can name the files as you choose - just make sure you can find them when I ask you for them.

Please add comments to your files so they're easy to read.