Computer Architecture Lab (Advanced)

Lesson 5 of 5

Practical Exam: Assembly Lab

The real test — hand-trace assembly, predict register values and debug a broken program under exam conditions.

🔴 Advanced 200 XP

Learn it

This is the practical assessment for the module. You will read low-level assembly and work out what it does with nothing but a pen and your understanding of the CPU.

Take the instruction set below, trace each program line by line in a register table, and only then answer.

Answer every question without running code — that is the challenge.

Key terms

Opcode
The part of an instruction that specifies which operation to perform.
Operand
The part of an instruction that specifies the data or address to operate on.
Trace table
A table recording the value of every variable and register after each executed instruction.
Branch
An instruction that changes the program counter, altering the order of execution.

Program A — what does it output?

text      INP          // read a number into the accumulator
      STA n
      LDA zero
      STA total
loop  LDA n
      BRZ end
      LDA total
      ADD n
      STA total
      LDA n
      SUB one
      STA n
      BRA loop
end   LDA total
      OUT
      HLT

n     DAT 0
total DAT 0
one   DAT 1
zero  DAT 0

Trace it with an input of 4 before you look at the quiz — the answer is not 4.

Try it

Trace Program A with an input of 4. What does OUT print?

textinput = 4
total = 0
while n != 0:
    total = total + n
    n = n - 1
print(total)

Challenge

Practical assessment. 1) Rewrite Program A so it computes n factorial instead of the running total, using only the instruction set above plus repeated addition. 2) Produce a complete trace table for an input of 3. 3) One bug has been planted below — find it, explain the symptom, and give the fix. INP STA n loop LDA n SUB one STA n BRP loop LDA n OUT HLT

Pick whichever way suits you — every mode earns the same bonus XP.

Write at least 40 more characters to submit.

Mark your own work

Guided walkthrough — 0/5 clues revealed

  1. Clue 1 locked — reveal it only if you get stuck.
  2. Clue 2 locked — reveal it only if you get stuck.
  3. Clue 3 locked — reveal it only if you get stuck.
  4. Clue 4 locked — reveal it only if you get stuck.
  5. Clue 5 locked — reveal it only if you get stuck.

Each clue costs 10 XP (never below 50 XP). You'd earn 100 XP right now.

Extension: Extend your factorial program to detect overflow beyond 999 and output an error code instead of a wrong answer.

Quiz time

Question 1 of 5Score 0

In the buggy program above, what does it actually output for an input of 3?