Decode a program with a loop, run it by hand, and count every bus transfer it makes.
Hardware context: Teaching processor with four registers on a bus. Reading a processor trace beside a bus trace
The teaching processor of lesson S0.6 holds the program below. An instruction is four hex digits: the kind, a register number, a spare 0, and an address or a second register number. The kinds are HALT 0, LOAD 1, ADD 2, STORE 3, SUB 4 and JUMPNZ 5. The PC starts at 0 and every register starts at 0.
This worksheet uses named constants. The first three entries show how to record your decisions.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
question | 8 | input of each check |
Full specification
| Box (address) | Content |
|---|---|
| 0 | 0x110B |
| 1 | 0x120C |
| 2 | 0x130D |
| 3 | 0x2001 |
| 4 | 0x4203 |
| 5 | 0x5203 |
| 6 | 0x300E |
| 7 | 0x0000 |
| 11 | 5 |
| 12 | 3 |
| 13 | 1 |
Every box not listed holds 0. Address 14 is the lamp register. Enter every answer as a plain decimal number.
| Entry | Your decision |
|---|---|
| KIND_0 | Kind digit of the instruction in box 0. |
| REG_0 | Register number in the instruction in box 0. |
| ADDR_0 | Address in the instruction in box 0, in decimal. |
| R1_VALUE | Value of r1 after the instruction in box 0 has run. |
| ROUNDS | Number of times the instruction in box 3 runs. |
| R0_FINAL | Value of r0 when the processor halts. |
| LAST_NEXT_PC | Address fetched right after the last time box 5 runs. |
| LAMPS | Value written to the lamp register. |
| LOADS | Number of bus reads made by LOAD instructions in the whole run. |
| STORES | Number of bus writes in the whole run. |
| FETCHES | Number of fetches in the whole run, counting the HALT. |
| TRANSFERS | Number of bus transfers of every kind in the whole run. |
| FETCHES_FOR_COUNT | How many fetches does the whole run make if box 12 starts with the value COUNT? |
Examples
Example 1
KIND 0- Input
Kind digit of the instruction in box 0.
- Output
matches = 1
The first hex digit of 0x110B is 1: LOAD.
Example 2
REG 0- Input
Register number in the instruction in box 0.
- Output
matches = 1
The second hex digit is 1, so the register is r1.
Example 3
ADDR 0- Input
Address in the instruction in box 0, in decimal.
- Output
matches = 1
The last hex digit is B, which is eleven.
Constraints and Contract
- Keep the parameter and named constants. Use the numeric codes and units on this page.
- For FETCHES_FOR_COUNT, enter a constant expression using COUNT. Only this entry changes with the parameter. The supported integer range is 1 through 16, inclusive.
Hints
Hint 1
Split each content into its four hex digits: kind, register, a spare 0, and the last digit.
Hint 2
A JUMPNZ whose address is smaller than its own box sends the PC back. The boxes in between repeat.
Hint 3
Every instruction is one fetch. Add one more transfer for each LOAD and each STORE that runs.
What the grader checks: Each check compares the full eight-bit answer. Parameter trials change one condition and keep the other decisions fixed.
13 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 1 problem on this path