Published by Patrick Mutisya · 14 days ago
By the end of this lesson you should be able to trace a simple assembly language program step‑by‑step, showing the contents of the program counter, registers and memory after each instruction.
Assembly language is a low‑level, human‑readable representation of machine code. Each instruction corresponds directly to an operation performed by the CPU. Typical components of an assembly language program are:
LD, ADD, ST).| Register | Purpose |
|---|---|
| PC (Program Counter) | Holds the address of the next instruction to be fetched. |
| ACC (Accumulator) | Used for arithmetic and logic operations. |
| IR (Instruction Register) | Temporarily stores the fetched instruction. |
The following program adds the contents of two memory locations (M[10] and M[11]) and stores the result in M[12].
; Simple addition program
LD 10 ; Load M[10] into ACC
ADD 11 ; Add M[11] to ACC
ST 12 ; Store ACC into M[12]
HLT ; Halt the processor
Assume the memory before execution contains the following values (all values are decimal):
| Address | Content |
|---|---|
| 10 | 7 |
| 11 | 5 |
| 12 | 0 |
Each row of the table shows the state of the system after the instruction has been executed.
| Step | PC | IR (Fetched Instruction) | ACC | Memory Change |
|---|---|---|---|---|
| 0 | 0 | — | 0 | Initial state |
| 1 | 1 | LD 10 | 7 | — |
| 2 | 2 | ADD 11 | 12 (\$7+5\$) | — |
| 3 | 3 | ST 12 | 12 | M[12] ← 12 |
| 4 | 4 | HLT | 12 | Program stops |
ST – the accumulator is the source, the memory address is the destination.Trace the following program. Assume the initial memory contents are M[20]=3, M[21]=4, M[22]=0.
LD 20
SUB 21
ST 22
HLT
Provide a trace table similar to the one above, showing the final value stored in M[22].