Worked example 1
Trace the following assembly program. Assume memory is initially all zeros. What is the final value stored in memory location 502?
Show solution outline
// Program Code
LDM #10 // Load the number 10 into the ACC
ADD #5 // Add the number 5 to the ACC
STO 502 // Store the ACC's content at address 502
END
Trace Table:
| Step | Instruction | ACC before | ACC after | Memory Changed |
|---|---|---|---|---|
| 1 | LDM #10 | 0 | 10 | - |
| --- | --- | --- | --- | --- |
| 2 | ADD #5 | 10 | 15 | - |
| 3 | STO 502 | 15 | 15 | M[502] = 15 |
Working:
- LDM #10: Immediate addressing. The value 10 is loaded directly into the Accumulator (ACC). ACC is now 10.
- ADD #5: Immediate addressing. The value 5 is added to the current content of the ACC (10). ACC becomes 10 + 5 = 15.
- STO 502: Direct addressing. The content of the ACC (15) is stored in the memory location with address 502.
Final Answer: The final value stored in memory location 502 is 15.