This simulator models a simple CPU containing 4 registers. Using the simulator, you can follow the progress of data as it traverses the CPU datapath from the registers to the ALU and back to the registers. In this simple simulator, there is no Control Unit. Instead, the user acts as the Control Unit by clicking knobs to select the appropriate registers and functions.
Machine Language The simulator uses a simple machine language. Since each memory cell can contain 16 bits, each machine language instruction is 16 bits long. The first 9 or 10 bits are used to determine the type of operation being performed. The last 6 bits are used to specify register numbers or memory addresses. (2 bits are sufficient for register numbers, because there are only 4 registers. 5 bits are sufficient for addressing main memory, since there are only 32 memory cells.)
Instructions: (See text in Chapter 10 for more detail)
1010000100 RR RR RR Add contents of last two registers, store result in the first listed 1010001000 RR RR RR Subtract contents of third register from second, store result in first 100000010 RR MMMMM Load contents from memory into register specified 100000100 RR MMMMM Store results from register into memory 100100010000 RR RR Copy contents from second register into first 1111111111111111 Halt the program
Example: Load the following program into memory ( Click on the box to the left of the memory cell to change it from Auto to 2 to indicate that you are entering values in binary. :
1000000100000101 (load memory location 5 into R0) 1000000100100110 (load memory location 6 into R1) 1010000100100001 (add R0 and R1, store result in R2) 1000001001000111 (Store data from R2 into memory location 7) 1111111111111111 (HALT) 0000000000001001 (data: 9 in binary) 0000000000000001 (data: 1 in binary)Execute the simulator to see what happens. Note that you no longer have to set the knobs yourself.
Assembler Language
It is too difficult to write programs in binary! Assembler language allow us to use words instead of binary codes.
For example, the instruction
1010000100000110 can be represented by ADD R0 R1 R2
The simulator allows you to enter instructions in assembly language. You can then view the instructions in either assembly language or in binary, by clicking on the
arrow next to the View As box to the left of the instruction.
Example: Load the following into memory and click on Execute:
LOAD R0 5 LOAD R1 6 ADD R2 R0 R1 STORE 7 R2 HALT 9 1