CS Unplugged activity
Little Man Computer: write your own
You’ve traced the little man’s programs on the last two sheets. Now write one yourself. A blank listing form is below each task: one line per mailbox, starting at address 00, same as every program you’ve traced so far.
How to fill in a line
- Write the mnemonic (
INP,ADD,STA, and so on) in the Mnemonic column. - If it needs one, write a label name or a mailbox number in the Operand column.
- If a line has a label of its own (so another line can jump to it), write that label in the Label column.
- Work out the Machine code: the mnemonic’s 3-digit code, with the operand’s mailbox number in the last two digits.
- Any number your program needs to store, not an instruction, gets its own
DATline at the end.
Task 1: Output the input times 2 (easy)
Take one number from the input tray and output double it. This is the same idea as “Double it” on the tracing sheet, just without the answer already filled in.
| Address | Label | Mnemonic | Operand | Machine code |
|---|---|---|---|---|
| 00 | ||||
| 01 | ||||
| 02 | ||||
| 03 | ||||
| 04 | ||||
| 05 | ||||
| 06 |
Test input: 6. Trace your own program with that input. If the output isn’t 12, something’s wrong.
Task 2: Subtract two inputs (medium)
Take two numbers from the input tray, in order, and output the first one minus the second one.
| Address | Label | Mnemonic | Operand | Machine code |
|---|---|---|---|---|
| 00 | ||||
| 01 | ||||
| 02 | ||||
| 03 | ||||
| 04 | ||||
| 05 | ||||
| 06 | ||||
| 07 | ||||
| 08 | ||||
| 09 |
Test input: 9, then 4. Trace your own program with those inputs. If the output isn’t 5, something’s wrong.
Task 3: Output the numbers from 1 up to the input (harder)
Take one number from the input tray, call it n, and output every number from 1 up to n, one at a time: if the input is 4, output 1, then 2, then 3, then 4. This needs a loop, so it’s the longest program on this sheet. Think back to the countdown loop from the branches sheet, but counting the other way, and stopping once you pass n instead of once you hit zero.
| Address | Label | Mnemonic | Operand | Machine code |
|---|---|---|---|---|
| 00 | ||||
| 01 | ||||
| 02 | ||||
| 03 | ||||
| 04 | ||||
| 05 | ||||
| 06 | ||||
| 07 | ||||
| 08 | ||||
| 09 | ||||
| 10 | ||||
| 11 | ||||
| 12 | ||||
| 13 | ||||
| 14 |
Test input: 4. Trace your own program with that input. If the outputs aren’t 1, 2, 3, 4 in that order, something’s wrong.
Checking your work
Trace your own program by hand, the same way you traced the ones on the last two sheets, using the test input given for each task. If your traced output matches, your program works.
Want a faster check? Type your machine code into a free online LMC simulator, such as Peter Higginson’s LMC simulator, and run it there instead. That’s optional, never required: everything on this sheet works with nothing but the paper and your pencil.
Version history
- Loading commit history…