Given the assembly code below:
| Hex Address | Label | Instruction |
|---|---|---|
| 100 | Load A | |
| 101 | Add One | |
| 102 | Jump S1 | |
| 103 | S2, | Add One |
| 104 | Store A | |
| 105 | Halt | |
| 106 | S1, | Add A |
| 107 | Jump S2 | |
| 108 | A, | HEX 0023 |
| 109 | One, | HEX 0001 |
a) List the hexadecimal code for the program (hand assemble it). b) What are the contents of the symbol table for this program? c) Write the program, compile and show the result in Marie.
| Part | Detail |
|---|---|
| Asks | (a) 4-digit hex word per line, (b) label → address table, (c) run it and give the final values. |
| Needs | Load 1, Store 2, Add 3, Halt 7, Jump 9; word = opcode digit + 3-digit address; HEX copied as is. |
| Look at | The labels S2, S1, A, One and their addresses; Jump changes the run order. |
| If it changes | Different labels or ORG change addresses and every word using them; opcode digits stay. |
Show solution ↓Hide solution ↑
How to solve
- Pass 1: every label gets the address of its line, giving the symbol table.
- Pass 2: for each instruction write opcode digit + the label’s address (Halt = 7000).
- Run: trace the AC, following jumps, until Halt.
| Address | Instruction | Opcode | Operand address | Hex |
|---|---|---|---|---|
| Symbol | Address |
|---|---|
| Addr run | Instruction | AC after | Memory change |
|---|---|---|---|
Sample answer
b) Symbol table
| Symbol | Address |
|---|---|
| S2 | 103 |
| S1 | 106 |
| A | 108 |
| One | 109 |
a) Hex code
| Address | Instruction | Opcode | Operand | Hex |
|---|---|---|---|---|
| 100 | Load A | 1 | 108 | 1108 |
| 101 | Add One | 3 | 109 | 3109 |
| 102 | Jump S1 | 9 | 106 | 9106 |
| 103 | S2, Add One | 3 | 109 | 3109 |
| 104 | Store A | 2 | 108 | 2108 |
| 105 | Halt | 7 | 000 | 7000 |
| 106 | S1, Add A | 3 | 108 | 3108 |
| 107 | Jump S2 | 9 | 103 | 9103 |
| 108 | A, HEX 0023 | 0023 | ||
| 109 | One, HEX 0001 | 0001 |
c) Program for the simulator
ORG 100
Load A
Add One
Jump S1
S2, Add One
Store A
Halt
S1, Add A
Jump S2
A, HEX 0023
One, HEX 0001
| Addr | Instruction | AC after | Memory change |
|---|---|---|---|
| 100 | Load A | 0023 | |
| 101 | Add One | 0024 | |
| 102 | Jump S1 | 0024 | |
| 106 | Add A | 0047 | |
| 107 | Jump S2 | 0047 | |
| 103 | Add One | 0048 | |
| 104 | Store A | 0048 | A (108) = 0048 |
| 105 | Halt | 0048 |
Result: AC = 0048, A = 0048 = 72. The program computes ().
Watch out:
Add Aat 106 adds the value stored in A (still 0023, becauseStore Ahas not run yet), not the AC.