Write a short program with a loop, as numbers in memory, and let the sixteen-box machine multiply.
Hardware context: Sixteen-box stored-program machine. First model of any processor
The machine of lesson S0.1 gains two instructions, so that a program can repeat steps. SUB n subtracts the content of box n from A. JUMPNZ n looks at A. If A is not 0, the PC becomes n, so the next instruction comes from box n. If A is 0, the PC steps to the next box as usual.
Write a program that multiplies by repeated addition. When the machine halts, box 13 must hold x times n. You write the content of boxes 0 to 12. Use the same program for every pair of inputs.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
sample | 10 | input of each check |
Full specification
| Instruction | What it does | Kind |
|---|---|---|
| HALT | Stop. | 0 |
| LOAD n | Copy the content of box n into A. | 1 |
| ADD n | Add the content of box n to A. | 2 |
| STORE n | Copy A into box n. | 3 |
| SUB n | Subtract the content of box n from A. | 4 |
| JUMPNZ n | If A is not 0, the PC becomes n. If A is 0, the PC steps on by one. | 5 |
| Box (address) | Content when the machine starts |
|---|---|
| 0 to 12 | the thirteen numbers you write: your program, and any data it needs |
| 13 | 0: the product must be here at the end |
| 14 | x |
| 15 | n, which is at least 1 |
An instruction is stored as kind times 16 plus the address. A box holds eight bits, and the product is never more than 255. The PC starts at 0 and A starts at 0. Your program may change any box, including 14 and 15.
Examples
Example 1
Two Rounds- Input
x = 3, n = 2
- Output
halted = 1, box13 = 6
The loop body runs twice and box 13 ends at 6.
Example 2
Three Rounds- Input
x = 5, n = 3
- Output
halted = 1, box13 = 15
Five is added three times.
Example 3
One Round- Input
x = 7, n = 1
- Output
halted = 1, box13 = 7
The loop body runs once and the jump is not taken.
Constraints and Contract
- Keep the module name, the six kind names and the thirteen constants BOX0 to BOX12. Each must be a constant.
- The machine must reach a HALT. A run that has not halted after 6,000 instructions is refused.
Hints
Hint 1
Keep a running total in box 13: load it, add x, store it back.
Hint 2
Count the rounds down in box 15. You need a box that holds the number 1.
Hint 3
Put JUMPNZ right after the count is stored, while A still holds the new count.
What the grader checks: The judge runs the submitted numbers on a private copy of the machine, with twenty pairs of x and n. For each pair it checks the halt flag and box 13.
20 checks on Icarus Verilog · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain your source only; samples require the simulation service. A passing result establishes the tested cases, not a proof for all possible inputs.
See all 2 problems on this path