AS · Practice questions · Tracing an assembly language program

Be the processor.

Six original Cambridge-style questions on tracing assembly language programs, with mark-scheme style solutions.

Original questions All questions on this page are original work, written in the Cambridge AS & A Level style. They are not from past papers. They test the same concepts and skills the syllabus rewards.
Keep these straight

Trace like the CPU.

01
Trace
[5 marks]
100  LDR #0
101  LDX 240
102  ADD 250
103  STO 250
104  INC IX
105  LDD 251
106  DEC ACC
107  STO 251
108  CMP #0
109  JPN 101
110  END

Memory: 240 holds 4, 241 holds 9, 242 holds 2, 250 holds 0, 251 holds 3. Trace the program and give the final contents of addresses 250 and 251, the IX and the ACC.

  • First pass: ACC = 4, 250 = 4, IX = 1, 251 = 2. ✓
  • Second pass: ACC = 9 + 4 = 13, 250 = 13, IX = 2, 251 = 1. ✓
  • Third pass: ACC = 2 + 13 = 15, 250 = 15, IX = 3, 251 = 0. ✓
  • CMP #0 is True, so JPN does not jump; the program ends. ✓
  • Final: 250 = 15, 251 = 0, IX = 3, ACC = 0. ✓
02
Trace
[4 marks]
100  LDM #0
101  STO 300
102  IN
103  CMP #46
104  JPE 109
105  LDD 300
106  INC ACC
107  STO 300
108  JMP 102
109  LDD 300
110  ADD #48
111  OUT
112  END

The user types the characters A, B and then a full stop. (ASCII: A is 65, B is 66, the full stop is 46, the character 0 is 48.) State the final contents of address 300 and the output, and describe what the program does.

  • 300 holds 2 (incremented for A and for B). ✓
  • When 46 is input, JPE jumps to 109; ACC = 2 + 48 = 50. ✓
  • OUT outputs the character 2. ✓
  • The program counts the characters typed before a full stop and outputs the count (as a digit). ✓
03
Explain
[2 marks]

Explain the difference between the instructions JPE and JPN.

  • JPE jumps to the given address if the previous compare was True. ✓
  • JPN jumps to the given address if the previous compare was False (otherwise the next instruction is executed). ✓
04
Trace
[3 marks]

Memory: 150 holds 152, 151 holds 7, 152 holds 20. Trace LDI 150, SUB 151, STO 151, CMI 150. Give the contents of the ACC and address 151, and state whether the compare is True or False.

  • LDI 150: 150 holds 152, which holds 20, so ACC = 20; SUB 151: ACC = 20 - 7 = 13. ✓
  • STO 151: address 151 = 13. ✓
  • CMI 150: compares the ACC (13) with the contents of 152 (20), so False. ✓
05
Write
[3 marks]

Write assembly language instructions, using the 9618 instruction set, to input a character and output it twice.

  • IN ✓
  • OUT ✓
  • OUT (followed by END); the ACC is not changed by OUT, so the second OUT outputs the same character. ✓
06
Analysis
[2 marks]

A loop is meant to run 4 times. The counter is stored at address 90 and starts at 4. The loop ends with LDD 90, DEC ACC, STO 90, CMP #1, JPN to the start of the loop. Explain why the loop does not run 4 times, and correct it.

  • The counter goes 3, 2, 1: the compare is True when it reaches 1, so the loop runs only 3 times. ✓
  • Compare with 0 instead: CMP #0. ✓

Mark this once you have attempted all six and checked your working. It records a Practiced badge on the topic and adds a one-time bonus. Revealing the solutions alone does not count.