Skip to content

9618 · 4.2

Assembly Language — practice questions

Practice and worked examples for 9618 Assembly Language. Short previews only — attempt the full question in MarkScheme against the official scheme.

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:

StepInstructionACC beforeACC afterMemory Changed
1LDM #10010-
---------------
2ADD #51015-
3STO 5021515M[502] = 15

Working:

  1. LDM #10: Immediate addressing. The value 10 is loaded directly into the Accumulator (ACC). ACC is now 10.
  2. ADD #5: Immediate addressing. The value 5 is added to the current content of the ACC (10). ACC becomes 10 + 5 = 15.
  3. 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.

Worked example 2

A program needs to find the largest number in a list of three numbers stored at memory addresses 200, 201, and 202. The values are: M[200]=7, M[201]=12, M[202]=5. Trace the program and state the final value in the Accumulator.

Show solution outline
// Program Code
LDX #0        // Initialise Index Register to 0
LDR 200,X     // Load first number into ACC
LOOP: INC X   // Increment Index Register
      CMP 200,X // Compare ACC with next number
      JPE ENDLOOP // If equal, no change needed
      JPN ENDLOOP // If ACC is greater, no change
      LDR 200,X // If new number is greater, load it
ENDLOOP: CMP X,#2 // Have we checked all numbers?
         JPN LOOP  // If IX < 2, loop again
END

Initial State: ACC=0, IX=0, M[200]=7, M[201]=12, M[202]=5

Trace Table:

InstructionIX beforeACC beforeComparisonIX afterACC afterNotes
LDX #000-00IX = 0
---------------------
LDR 200,X00-07ACC = M[200+0] = 7
LOOP 1
INC X07-17IX is now 1
---------------------
CMP 200,X177 vs 1217Compare ACC(7) with M201
JPE ENDLOOP17False17Not equal, continue
JPN ENDLOOP17False17ACC is not greater, continue
LDR 200,X17-112New number is larger, ACC = M[201] = 12
CMP X,#21121 vs 2112IX < 2, so loop again
JPN LOOP112True112Jump to LOOP
LOOP 2
INC X112-212IX is now 2
---------------------
CMP 200,X21212 vs 5212Compare ACC(12) with M202
JPE ENDLOOP212False212Not equal, continue
JPN ENDLOOP212True212ACC is greater, jump to ENDLOOP
CMP X,#22122 vs 2212IX is not less than 2
JPN LOOP212False212Do not jump, continue to END

Final Answer: The program terminates with the value 12 in the Accumulator.