Assembly language & Little Man Computer
Computer Science · Computer architecture & systems
Question 1 of 10
0In Little Man Computer machine code the opcodes are LDA = 5xx, STA = 3xx, ADD = 1xx, SUB = 2xx, BRA = 6xx, BRZ = 7xx, BRP = 8xx (xx is the mailbox address). What three-digit machine code represents BRP 12?
Decimals (0.75 or 0,75), fractions (3/4) and mixed numbers (1 1/2) are accepted. Do not use thousands separators.
How to type your answer
- Fractions: 3/4. Mixed numbers: 1 1/2.
- Decimals with a point or a comma: 0.75 or 0,75.
- Negative numbers start with a minus: -3/4.
- Percentages need the % sign: 75%.
Stuck? Read the explanation
Unlocks at a streak of 5 correct answers in a row.
Embed this practice on your site or class page
Paste this HTML into your page. Students practise right there; it is free and needs no account.
Assembly language & Little Man Computer explained
Assembly language uses short mnemonic codes, such as LDA for load, to represent the machine code instructions that a CPU understands. Each mnemonic corresponds to one machine instruction, and an assembler translates the program into machine code. The Little Man Computer (LMC) is a teaching model of a simple computer with 100 memory mailboxes, numbered 0 to 99, each holding a three-digit value from 000 to 999. It has one accumulator, which holds the result of calculations.
Each LMC instruction is a three-digit number. The first digit is the opcode, which says what to do, and the last two digits are the mailbox address the instruction uses. The key instructions are INP (901), which reads a value from the input into the accumulator; OUT (902), which displays the accumulator; STA (3xx), which stores the accumulator in mailbox xx; LDA (5xx), which loads mailbox xx into the accumulator; ADD (1xx) and SUB (2xx), which add or subtract mailbox xx; BRA (6xx), which jumps to mailbox xx; BRZ (7xx) and BRP (8xx), which jump if the accumulator is zero or positive; and HLT (000), which stops the program. DAT stores a value in a mailbox for use as data.
Worked example
The program below reads two numbers, adds them, and outputs the result. Mailboxes 0 to 5 hold the code and mailbox 10 holds a working value.
- 901 INP reads the first number into the accumulator.
- 310 STA 10 stores it in mailbox 10. 901 INP then reads the second number.
- 110 ADD 10 adds the stored value, 902 OUT displays the total, and 000 HLT stops.
With inputs 5 and 7, the output is .
What you will practise
New numbers every time you practise. Levels: Easy, Medium, Hard. Each answer is followed by a worked explanation.
Example questions
Easy
Little Man Computer program (standard mnemonics, one instruction per mailbox, execution starts at mailbox 0): [0: LDA 5; 1: ADD 6; 2: SUB 7; 3: OUT; 4: HLT; 5: DAT 21; 6: DAT 22; 7: DAT 5]. What number does the program output?
Medium
Little Man Computer program (standard mnemonics, one instruction per mailbox, execution starts at mailbox 0): [0: INP; 1: SUB 10; 2: BRP 6; 3: LDA 11; 4: OUT; 5: HLT; 6: LDA 12; 7: OUT; 8: HLT; 10: DAT 50; 11: DAT 1; 12: DAT 410]. BRP branches if the accumulator is zero or positive; BRZ branches if it is zero. Inputs in order: 42. What number is output?
Hard
Little Man Computer program (standard mnemonics, one instruction per mailbox, execution starts at mailbox 0): [0: INP; 1: STA 15; 2: INP; 3: STA 16; 4: SUB 15; 5: BRP 10; 6: LDA 15; 7: ADD 15; 8: OUT; 9: HLT; 10: LDA 16; 11: ADD 16; 12: OUT; 13: HLT; 15: DAT 0; 16: DAT 0]. BRP branches if the accumulator is zero or positive; BRZ branches if it is zero. Inputs in order: 71, 94. What number is output?