S2.5.2 One Wrong Control Bit

MediumDebug25 minIcarus Verilog · serverReview the topic

A core passes its three test programs. In a longer program, a register that no instruction names changes its value. One column of the control table is to blame. Find it and repair it.

Hardware context: The main decoder of a single-cycle RV32I core as a control table of six opcodes that steers the datapath of ap_rv32_sc, and the ALU decoder of the real core. Writing and reviewing the decoder of a processor

A team writes the control table of a small core as logic: one line for each column. The core has the six kinds of instruction of the lesson. Its three test programs pass.

Then a longer program fails. Register x25 holds a value that the program never wrote. No instruction of the program has x25 as its rd. Repair the decoder. It has no clock.

Signals in the Timeline

SignalWidthRole
trial10input of each check
Full specification
What the datapath does with the outputs
These are the signals of the lesson, with the same meaning.
OutputMeaning
reg_write1: the register named by bits 11 to 7 of the word takes the result at the clock edge.
alu_b_select0: the second ALU operand is rs2_data. 1: it is the immediate.
result_select0: the result is the ALU result. 1: the loaded value. 2: the PC plus 4.
mem_read, mem_write1: a load, or a store.
branch, jump1: a conditional branch, or a jal.

This core has six kinds of instruction and no others: OP, OP_IMM, LOAD, STORE, BRANCH and JAL. Any other word must change nothing: no register, no memory word and no jump.

How to read a result: a public case shows the five enables for one opcode. A private case tries many opcodes, and all_match is 1 when every one was right.

Examples

Example 1

Arithmetic
Input
the opcode 0110011: add, sub and the like
Output
reg_write = 1, mem_read = 0, mem_write = 0, branch = 0, jump = 0

Arithmetic on two registers writes rd. The starter gets this right.

Example 2

A Store
Input
the opcode 0100011: a store
Output
reg_write = 0, mem_read = 0, mem_write = 1, branch = 0, jump = 0

A store writes the memory and no register. The starter gets this right too.

Example 3

A Branch
Input
the opcode 1100011: a branch
Output
reg_write = 0, mem_read = 0, mem_write = 0, branch = 1, jump = 0

A branch changes only the PC. Its bits 11 to 7 are a part of the offset, not a register to write.

Constraints and Contract

  • The outputs depend only on the opcode of the same moment. The bench waits 1 ns after it sets it.
  • The five enables are checked for all 128 values of the opcode: reg_write, mem_read, mem_write, branch and jump.
  • alu_b_select and result_select are checked only where the datapath uses them.

Hints

Hint 1

Which kinds of instruction have no rd? In those words, bits 11 to 7 hold something else.

Hint 2

Write the offset of a branch in binary, and look at the five bits that sit where rd would be.

Hint 3

After the repair, ask what your column says for a word that is no instruction at all.

What the grader checks: All 128 values of the seven opcode bits. Among them are the six kinds, and five opcodes of instructions that this core lacks.

7 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

Report a problem with this page

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

Arithmetic

Input
the opcode 0110011: add, sub and the like
Expected output
reg_write = 1, mem_read = 0, mem_write = 0, branch = 0, jump = 0

Arithmetic on two registers writes rd. The starter gets this right.

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

Icarus Verilog · server