S0.6.1 Count the Transfers

EasyImplement12 minIcarus Verilog · serverReview the topic

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

SignalWidthRole
question8input of each check
Full specification
Box (address)Content
00x110B
10x120C
20x130D
30x2001
40x4203
50x5203
60x300E
70x0000
115
123
131

Every box not listed holds 0. Address 14 is the lamp register. Enter every answer as a plain decimal number.

EntryYour decision
KIND_0Kind digit of the instruction in box 0.
REG_0Register number in the instruction in box 0.
ADDR_0Address in the instruction in box 0, in decimal.
R1_VALUEValue of r1 after the instruction in box 0 has run.
ROUNDSNumber of times the instruction in box 3 runs.
R0_FINALValue of r0 when the processor halts.
LAST_NEXT_PCAddress fetched right after the last time box 5 runs.
LAMPSValue written to the lamp register.
LOADSNumber of bus reads made by LOAD instructions in the whole run.
STORESNumber of bus writes in the whole run.
FETCHESNumber of fetches in the whole run, counting the HALT.
TRANSFERSNumber of bus transfers of every kind in the whole run.
FETCHES_FOR_COUNTHow 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

Report a problem with this page

Your code SystemVerilogSaved locally
Ln 1, Col 1Tab indents · Ctrl/⌘ + Enter runs samples
Not run yet

KIND 0

Input
Kind digit of the instruction in box 0.
Expected output
matches = 1

The first hex digit of 0x110B is 1: LOAD.

Run samples executes all 3 public checks. Check all tests runs 13 checks on the server.

Icarus Verilog · server