Lesson
The theory — Tiny CPU: the Little Man Computer
The fetch–decode–execute cycle is what a processor does with every instruction. Fetch copies PC into MAR, reads that mailbox into MDR, copies it into CIR and adds 1 to PC. Decode splits the instruction into an operation (the hundreds digit) and an address (the last two digits), except for 901, 902 and 000, which are whole codes for INP, OUT and HLT and name no mailbox. Execute carries it out, which may read or write one more mailbox through MAR and MDR.
What each symbol means
PC- program counter: the address of the next instruction to fetch
MAR- memory address register: the mailbox about to be read or written
MDR- memory data register: the value just read, or about to be written
CIR- current instruction register: the instruction being run
ACC- accumulator: where ADD, SUB and LDA put their result
- Assumes
- Stuart Madnick's Little Man Computer (MIT, 1965) leaves undefined what happens when SUB goes below zero or ADD passes 999. This machine's accumulator holds −999 to 999, so BRP tests a sign, and a result outside that range stops the run with an overflow instead of wrapping. School simulators differ on this point, and a program whose accumulator stays between 0 and 999 runs the same on all of them.
Problem solved in full
-
Why 2 × 99 costs 801 instructions and 99 × 2 costs 25 4 steps
Press 2 × 99, the slow way, then change the inputs to 99, 2. Both print 198. Count the instructions each run executes, find the formula, and say what the worst order costs for a product that fits in a mailbox.
-
Before the loop, two INP and two STA: 4 instructions. The loop body runs LDA b, BRZ, SUB one, STA b, LDA total, ADD a, STA total, BRA loop: 8 instructions, once for each unit of b.
-
When b reaches zero the loop runs only LDA b and BRZ, then LDA total, OUT and HLT finish: 5 more. So a run costs 4 + 8b + 5 = 8b + 9, and a does not appear at all.
-
With b = 99 that is 8 × 99 + 9 = 801; with b = 2 it is 25. The results table prints 801 for the first order and 25 for the second.
-
The largest product a mailbox holds is 999. Typed as 1, 999, the loop runs 999 times: 8,001 instructions. Typed as 999, 1, it runs once: 17.
Answer
8b + 9 instructions, with b the second input. The same 999 costs 8,001 instructions one way round and 17 the other, about 470 times as many, and a program that compared its inputs first and looped over the smaller would never pay more than 8 × 31 + 9 plus the comparison, since the smaller factor of a product up to 999 is at most 31.
-
Learning path
How a computer runs a program
References (4)
- Where the third insight's phrase comes from: the connecting tube between CPU and store, named the von Neumann bottleneck, and the remark that much of its traffic is not data but the names of data: John Backus, "Can programming be liberated from the von Neumann style? A functional style and its algebra of programs." Communications of the ACM 21(8), 613–641, August 1978. The 1977 ACM Turing Award Lecture.
- The date the first insight gives for the stored-program idea first running: The University of Manchester, "How a 70-year-old 'Baby' changed the face of modern computing." News, 21 June 2018.
- The machine itself: Madnick's 1965 design, the instruction codes, and the fact the page's assumes rests on, that a negative or over-999 result is left undefined: "Little man computer." Wikipedia, read 14 October 2026.
- A school simulator's instruction table, with BRP described as branching when the accumulator is zero or positive, the sign convention this page follows: 101computing.net, "LMC Simulator."