Computer Architecture, Assembly and the LMC
Assembly language is a low-level programming language that uses short mnemonics, such as LDA or ADD, in place of raw binary machine code, with each assembly instruction normally corresponding to exactly one machine code instruction; an assembler translates assembly language into the object code the processor actually runs. The Little Man Computer (LMC) is a simplified, decimal-based model of a stored-program (von Neumann) computer, with 100 numbered mailboxes (00 to 99) of memory, a single Accumulator, and a small instruction set (INP, OUT, LDA, STA, ADD, SUB, BRA, BRZ, BRP, HLT, DAT), used to practise writing and tracing simple programs and to make the fetch-execute cycle from A1.1 concrete. It also covers addressing modes: immediate, direct, indirect and indexed, which describe how an instruction's operand specifies where its data actually is.
Before you start
Make sure you're comfortable with these topics first:
Method
- Learn each LMC mnemonic's numeric opcode range (1xx ADD, 2xx SUB, 3xx STA, 5xx LDA, 6xx BRA, 7xx BRZ, 8xx BRP, 901 INP, 902 OUT, 000 HLT) before trying to trace a program.
- When tracing an LMC program, keep a running row for the Accumulator and every mailbox named by a DAT line, updating only the values changed by each instruction as you step through the program in order.
- Recognise BRZ as 'branch if the Accumulator equals exactly zero' and BRP as 'branch if the Accumulator is zero or positive' - check the Accumulator's exact value before deciding whether a branch is taken.
- Build loops in LMC by decrementing a counter mailbox on each pass and using BRZ (or BRP) to jump back to a label while the counter has not yet reached the exit condition.
- Distinguish the four addressing modes by what the instruction's operand actually represents: immediate (the value itself), direct (the address of the value), indirect (the address of an address of the value), and indexed (a base address plus an index register's offset).
- Link assembly-level detail back to A1.1: each LMC instruction mirrors the fetch-decode-execute cycle, with LDA/STA moving data between the Accumulator and memory much as MDR/MAR do in a real processor.
Worked example
The following Little Man Computer (LMC) program is assembled and run. Two values, 4 and then 7, are entered when the program executes its two INP instructions, in that order. INP STA NUM1 INP ADD NUM1 OUT HLT NUM1 DAT 000 Trace the program and state the value it outputs.
- INP reads the first input into the Accumulator: ACC = 4.
- STA NUM1 copies the Accumulator into the mailbox labelled NUM1, so NUM1 = 4; the Accumulator itself is unchanged (still 4).
- INP reads the second input into the Accumulator, overwriting its previous value: ACC = 7.
- ADD NUM1 adds the value stored at NUM1 to the Accumulator: ACC = 7 + 4 = 11.
- OUT outputs the current value of the Accumulator, and HLT stops the program.
- Final answer: the program outputs 11.
Practice questions
Type your answer and press Check to be marked straight away, or reveal the answer and mark yourself.
Q1State the LMC mnemonic for the opcode 5xx.Show answer
Answer: LDA (load the value at the given mailbox into the Accumulator).
Q2State what the LMC instruction BRZ 14 does.Show answer
Answer: It branches (jumps) to mailbox address 14 only if the Accumulator currently holds exactly 0; otherwise execution continues with the next instruction as normal.
Q3An LMC mailbox holds a 3-digit value. State the base (number system) the Little Man Computer uses to store values, and contrast this with a real processor.Show answer
Answer: Decimal (denary); a real processor stores every value in binary, but the LMC uses denary values (000 to 999) to make programs easier for a learner to read and trace.
Q4In assembly language, state what an assembler does.Show answer
Answer: It translates assembly language source code into the machine code (object code) that the processor can actually fetch and execute, normally translating each assembly instruction into exactly one machine code instruction.
Q5An instruction's operand is the value 25 itself, rather than an address. State the addressing mode being used.Show answer
Answer: Immediate addressing.
Q6An instruction uses indexed addressing with a base address of 200 and an index register holding 3. State the effective (actual) address the instruction accesses.Show answer
Answer: 203 (the base address 200 plus the index register's offset of 3).
Q7Explain the difference between direct addressing and indirect addressing.Show answer
Answer: In direct addressing, the operand is the actual address of the data value. In indirect addressing, the operand is the address of a location that itself holds the address of the data value, adding one extra level of lookup.
Q8State the value the Accumulator holds immediately after the LMC instruction HLT executes.Show answer
Answer: HLT does not change the Accumulator; it simply stops the program running, so the Accumulator keeps whatever value it held immediately before HLT executed.
Exam-style questions
Written in the style of a A Level Computer Science exam paper, with a full mark scheme.
Explain, using the terms mailbox and Accumulator, what happens when the LMC instruction ADD 08 executes.
Show mark scheme
Tick each line you got. Your score builds from the marks on the scheme.
Nothing ticked yet - 2 available
The following LMC program is assembled and run. The value 3 is entered at the first INP, and the value 4 is entered at the second INP. INP STA NUM1 INP STA COUNT LOOP LDA COUNT BRZ ENDLOOP LDA TOTAL ADD NUM1 STA TOTAL LDA COUNT SUB ONE STA COUNT BRA LOOP ENDLOOP LDA TOTAL OUT HLT NUM1 DAT 000 COUNT DAT 000 TOTAL DAT 000 ONE DAT 001 Complete a trace table showing the value of COUNT and TOTAL at the end of each pass through the loop (the block of instructions from LOOP to BRA LOOP), and state the value the program outputs.
Show mark scheme
Tick each line you got. Your score builds from the marks on the scheme.
Nothing ticked yet - 6 available
A processor instruction can use immediate, direct or indexed addressing to access an operand. For each of these three addressing modes, state what the instruction's operand actually represents.
Show mark scheme
Tick each line you got. Your score builds from the marks on the scheme.
Nothing ticked yet - 3 available
See real A Level Computer Science past-paper questions, with official mark schemes →
Free printable worksheet
Want more practice on paper? Download the computer architecture, assembly and the lmc worksheet pack - 10 pages of exam-style questions with a full mark scheme. One email opens every download in this browser for 14 days - no account, no card. Print it for personal and classroom use.
Next topics
Not quite what you needed?
Tell us what is missing on computer architecture, assembly and the lmc, or which topic to write up next. Every request is read, and we reply to every one.
Build a full practice pack.
This topic is one of hundreds in the library - pick the ones a student needs and generate a printable PDF in minutes.