Skip to content
MathsGenie logo
Quick links
Open app

Course home

  1. A Level
  2. Computer Science OCR
  3. Revision guides

Little Man Computer instruction set

What you'll learn

  • What the Little Man Computer is modelling.
  • How LMC instructions are written using mnemonics such as LDA, ADD, and BRZ.
  • What each OCR H446 LMC instruction does.
  • How to trace a short LMC program using the accumulator, memory, and output.

The big picture: what LMC is for

The Little Man Computer, usually shortened to LMC, is a simplified model of a computer. It helps you understand how a processor fetches, decodes, and executes instructions stored in memory.

LMC has:

  • Memory, made of numbered mailboxes, usually addresses 00 to 99.
  • An accumulator, which is a special storage location used for arithmetic and data movement.
  • An input area, where values can enter the program.
  • An output area, where values can be displayed.
  • A program counter, which keeps track of the next instruction to fetch.
Definition

Instruction set

An instruction set is the complete list of instructions that a processor, or simulated processor such as LMC, can understand and execute.

The diagram below shows how LMC links together memory, the accumulator, input/output, and the fetch-decode-execute cycle.

Labelled Little Man Computer schematic showing mailboxes, program counter, current instruction register, accumulator, input/output, and instruction format

Mnemonics and machine instructions

A mnemonic is a short, memorable assembly-language word for an instruction. For example, ADD means “add”, and SUB means “subtract”.

In OCR questions, the official mnemonics are the ones in the left-hand column of the specification table. Some alternative mnemonics are accepted in learners’ answers, but it is safest to use the official OCR ones.

Key Idea

Use the OCR mnemonics

Write STA, LDA, BRA, BRZ, BRP, INP, OUT, and HLT in exam answers unless the question itself uses an accepted alternative.

LMC instruction format

Most LMC instructions are stored as three-digit codes.

  • The first digit is usually the opcode, meaning the operation to perform.
  • The last two digits are usually the operand address, meaning the mailbox address the instruction uses.

For example, 194 means:

  • opcode 1 → ADD
  • operand address 94 → use mailbox 94

So 194 means ADD 94.

Definition

Opcode and operand

The opcode says what operation to perform. The operand gives the data or address used by that operation. In LMC, the operand is usually a two-digit mailbox address.

Example

Decoding an LMC instruction

Suppose the instruction fetched from memory is 594.

  1. Split the instruction into its opcode and operand: opcode 5, operand address 94.
  2. Match the opcode to the LMC instruction set: opcode 5 means LDA.
  3. Interpret the full instruction: LDA 94 means load the value stored in mailbox 94 into the accumulator.

The LMC instruction set

Here is the OCR H446 instruction set, with common machine-code patterns included to help you recognise what is happening.

MnemonicInstructionTypical LMC code patternWhat it doesAlternative mnemonics accepted
ADDAdd1xxAdds the value in mailbox xx to the accumulator
SUBSubtract2xxSubtracts the value in mailbox xx from the accumulator
STAStore3xxStores the accumulator value into mailbox xxSTO
LDALoad5xxLoads the value from mailbox xx into the accumulatorLOAD
BRABranch always6xxAlways jumps to instruction at address xxBR
BRZBranch if zero7xxJumps to address xx if the accumulator is zeroBZ
BRPBranch if positive8xxJumps to address xx if the accumulator is positiveBP
INPInput901Takes user input into the accumulatorIN, INPUT
OUTOutput902Outputs the value currently in the accumulator
HLTEnd program000Stops executionCOB, END
DATData locationdata valueReserves a mailbox for data

Data movement: LDA, STA, and DAT

Three of the most important LMC instructions are about moving data.

LDA — load

LDA xx copies the value from mailbox xx into the accumulator.

Example: LDA 90 means “load the value from mailbox 90 into the accumulator”.

STA — store

STA xx copies the current value in the accumulator into mailbox xx.

Example: STA 91 means “store the accumulator value in mailbox 91”.

DAT — data location

DAT marks a mailbox as a place for data rather than an instruction. It can be empty or initialised with a value, such as DAT 005.

Common Mistake

Mixing up LDA and STA

LDA loads from memory into the accumulator. STA stores from the accumulator into memory. The direction is the key difference.

Example

Tracing load, add, and store

Consider this section of an LMC program.

AddressInstructionMeaning
00LDA 90Load value from mailbox 90
01ADD 91Add value from mailbox 91
02STA 92Store result in mailbox 92
90DAT 007Data value 7
91DAT 005Data value 5
92DAT 000Space for result
  1. LDA 90 copies the value in mailbox 90 into the accumulator, so the accumulator becomes 7.
  2. ADD 91 adds the value in mailbox 91, so the accumulator becomes 12.
  3. STA 92 copies the accumulator value into mailbox 92, so mailbox 92 now stores 12.

Arithmetic: ADD and SUB

The accumulator is the working area for calculations.

ADD

ADD xx adds the value in mailbox xx to the accumulator. The result stays in the accumulator.

SUB

SUB xx subtracts the value in mailbox xx from the accumulator. Again, the result stays in the accumulator.

Tip

Accumulator thinking

For ADD and SUB, read the instruction as: “new accumulator value equals old accumulator value combined with the value at the given mailbox.”

Input and output: INP and OUT

INP

INP takes a value from the user and places it in the accumulator. It does not need a mailbox address.

OUT

OUT outputs the current value in the accumulator. It also does not need a mailbox address.

Example

Tracing an input-and-add program

This program inputs two numbers, adds them, and outputs the result.

AddressInstructionComment
00INPInput first number
01STA 90Store it in mailbox 90
02INPInput second number
03ADD 90Add first number
04OUTOutput total
05HLTStop
90DATStorage for first number

Suppose the inputs are 7 then 5.

  1. INP at address 00 places the first input, 7, in the accumulator.
  2. STA 90 stores 7 in mailbox 90, so the program does not lose it when the second input arrives.
  3. INP at address 02 replaces the accumulator value with the second input, 5.
  4. ADD 90 adds the stored value 7 to the accumulator, giving 12.
  5. OUT outputs 12, then HLT stops the program.

Branching: changing the order of execution

Normally, LMC executes instructions in address order: 00, then 01, then 02, and so on.

A branch instruction changes this by setting the program counter to a different address. This is how LMC programs make decisions and loops.

BRA — branch always

BRA xx always jumps to address xx.

Use it for unconditional jumps, such as returning to the start of a loop.

BRZ — branch if zero

BRZ xx jumps to address xx only if the accumulator is zero.

If the accumulator is not zero, execution continues with the next instruction.

BRP — branch if positive

BRP xx jumps to address xx only if the accumulator is positive.

Common Mistake

Branching checks the accumulator

BRZ and BRP test the value in the accumulator, not the value in the mailbox named by the operand.

Example

Following a conditional branch

Consider this program fragment.

AddressInstructionComment
00LDA 90Load test value
01BRZ 04If accumulator is zero, jump to 04
02LDA 91Load output value
03OUTOutput it
04HLTStop
90DAT 000Test value
91DAT 123Output value
  1. LDA 90 loads the value in mailbox 90, so the accumulator becomes 0.
  2. BRZ 04 checks the accumulator. Because it is zero, the program counter jumps to address 04.
  3. Address 04 contains HLT, so the program stops. The instructions at addresses 02 and 03 are skipped.

Ending a program: HLT

HLT stops the program. In typical LMC machine code it is represented as 000.

Without a halt instruction, the program may continue into memory locations that were meant to be data.

Common Mistake

Do not execute data accidentally

DAT reserves a mailbox for data, but memory still only stores numbers. If the program counter reaches a data mailbox, the LMC may try to treat that data as an instruction. Use HLT or branches to avoid falling into data storage.

Accepted alternatives in answers

OCR states that questions will use the official mnemonics in the left-hand column. However, the following alternatives are accepted:

Official mnemonicAccepted alternative
STASTO
LDALOAD
BRABR
BRZBZ
BRPBP
INPIN, INPUT
HLTCOB, END

There are no listed alternatives for ADD, SUB, OUT, or DAT.

Tip

Best habit

Even though alternatives may be accepted, use the OCR official mnemonics consistently. It reduces the chance of ambiguity when tracing or writing LMC code.

Exam technique

In the exam

  1. Keep a trace table with columns for address, instruction, accumulator, changed mailbox values, and output.
  2. For BRZ and BRP, always check the accumulator value before deciding whether the branch is taken.
  3. Remember that INP overwrites the accumulator, so store important input values with STA before another input happens.
Self review

Check yourself

  • What is the difference between LDA 90 and STA 90?
  • Which instruction would you use to jump only when the accumulator is zero?
  • Why is it risky if execution reaches a DAT mailbox?
PreviousNext

How was this guide?

Teach Genie

Review Little Man Computer instruction set by teaching Genie

Teach it back in your own words, spot gaps, and remember it better.

Start teaching
Genie and Baby Genie

Lesson

Recap your knowledge with an interactive lesson

8 minute activity

Start lesson

Labelled Little Man Computer schematic showing the program counter pointing to mailbox 02, instruction 594 split into opcode 5 and operand address 94, and arrows linking memory, accumulator, input, and output

The Little Man Computer, or LMC, is a simplified model of a stored-program computer. It helps you see how instructions are fetched from memory, decoded, and executed one at a time.

LMC has numbered memory mailboxes, an accumulator for the current working value, a program counter for the next instruction, and input and output boxes. Its instruction set is the complete list of instructions that the machine can understand.

Flashcards

Remember key concepts with flashcards

23 flashcards

Practice flashcards

LMC memory is made of numbered [     ], usually addressed [     ].

Little Man Computer instruction set Revision Guide

  1. A Level
  2. /Computer Science
  3. /Little Man Computer instruction set

Revision guides