- Reference: The 8 bit computer simulation
- Last class we looked at the program:
address instruction
0 load A
1 add B
2 store C
3 output
4 halt
A 10
B 20
C
- We would like to make it so we can run this program on the 8 bit computer.
- This means we need to "assemble" the program or move it from assembly code to machine code.
- Note in the op codes box, the opcode is given for each instruction.
- The basic instruction format is
opcode address
- So
0x26
- Has an opcode of 2, or add
- And a memory address of 6
- This will add the value at memory address 6 to the A register.
- Some operations have different arguments
- loadi loads the 4 bit value into register a.
- 0x50 will load a 0 into register A.
- output, and halt do not take any arguments, so any value will do.
- Normally this is a 0.
- We are starting at an advantage/disadvantage
- The 8 bit computer starts executing at address 0
- There are no segments (there is too little memory)
- So we just put the data after the program.
- Note this means, that A is at 5, B is at 6 and C is at 7.
- In "real" computers
- The different segments "live" at different places in memory
- So our program becomes
address instruction
0 load 5
1 add 6
2 store 7
3 output 0
4 halt 0
5 10
6 20
7
- The rest of the translation to machine code is easy
- For each mnemonic, replace it with the op code.
- load -> 1
- add -> 2
- store -> 4
- output -> E
- halt -> F
- So the program becomes
address instruction
0 1 5
1 2 6
2 4 7
3 E 0
4 F 0
5 10
6 20
7
- Since the instructions are in hex, we need to change that to be 0x
- The simulation will either use hex or decimal
- The program becomes
0x15 0x26 0x47 0xE0 0XF0 10 20
- We can run this in the simulator by
- Pasting the program into the Program line.
- Press load (far right)
- Press Reset
- Press Run, Step or μStep as desired.