R11.5.2 Pick the Style for the Brief

MediumImplementIcarus Verilog + Yosys · serverReview the topic

Write an ALU control decoder whose brief says what every unlisted opcode must do, with no latch and no unknown output.

Hardware context: A packet-kind decoder that lists five of eight kinds behind a full_case attribute; and an ALU control decoder with nine of sixteen opcodes and an enable. Design the ALU control decoder so that reserved opcodes do nothing and raise err.

A small processor decodes a 4-bit opcode into a control word for its ALU. Nine opcodes exist. The other seven are reserved for a later version. Software that runs on the wrong version of the chip will send them.

The brief is firm about that case. A reserved opcode must do nothing: no write, all control bits 0. It must also raise err, so the processor can trap. When en is 0 there is no instruction: every output is 0 and err is 0, whatever op holds.

This is an Implement problem: write the body of alu_ctl. The fixture applies twelve steps of en and op, one per nanosecond, and records the control word after each. A design that holds a value, or shows an unknown, fails at the step after.

Brief: inputs en and op[3:0]; outputs sel[2:0], use_imm, we and err; combinational; no latch. Synthesis check: the design must build on the site's synthesis flow with no latch. The cell and level counts come from an open-source flow and are a proxy for area and depth, not a foundry result.

Signals in the Timeline

SignalWidthRole
script60input of each check
Full specification
The module (keep the name and the ports)
module alu_ctl (
  input  logic       en,           // 0: no instruction this cycle
  input  logic [3:0] op,
  output logic [2:0] sel,          // which ALU function
  output logic       use_imm,      // 1: the second operand is the immediate
  output logic       we,           // 1: write the result register
  output logic       err           // 1: en is 1 and op is not an instruction
);
  // your design
endmodule
opInstructionseluse_immwe
0ADD001
1SUB101
2AND201
3OR301
4XOR401
8ADDI011
10ANDI211
12CMP100
13CMPI110
Casesel, use_imm, weerr
en = 1 and op in the tablefrom the table0
en = 1 and any other op (5, 6, 7, 9, 11, 14, 15)all 01
en = 0, any opall 00

The result holds the control word after each of the 12 steps: sel, use_imm, we and err.

Examples

Example 1

Every Instruction
Input
ADD, SUB, AND, OR, XOR, ADDI, ANDI, CMP, CMPI, XOR, CMPI, ADD
Output
sel_step0 = 0, imm_step0 = no, we_step0 = yes, sel_step1 = 1, imm_step1 = no, we_step1 = yes, sel_step2 = 2, imm_step2 = no, we_step2 = yes, sel_step3 = 3, imm_step3 = no, we_step3 = yes, sel_step4 = 4, imm_step4 = no, we_step4 = yes, sel_step5 = 0, imm_step5 = yes, we_step5 = yes, sel_step6 = 2, imm_step6 = yes, we_step6 = yes, sel_step7 = 1, imm_step7 = no, we_step7 = no, sel_step8 = 1, imm_step8 = yes, we_step8 = no, sel_step9 = 4, imm_step9 = no, we_step9 = yes, sel_step10 = 1, imm_step10 = yes, we_step10 = no, sel_step11 = 0, imm_step11 = no, we_step11 = yes

Each of the nine opcodes gives its row of the table, and err stays 0.

Example 2

An Unlisted Opcode After Each Kind of Instruction
Input
SUB, op 5, ANDI, op 6, CMPI, op 7, XOR, op 9, ADDI, op 11, OR, op 14
Output
sel_step0 = 1, imm_step0 = no, we_step0 = yes, sel_step1 = 0, imm_step1 = no, we_step1 = no, err_step1 = yes, sel_step2 = 2, imm_step2 = yes, we_step2 = yes, sel_step3 = 0, imm_step3 = no, we_step3 = no, err_step3 = yes, sel_step4 = 1, imm_step4 = yes, we_step4 = no, sel_step5 = 0, imm_step5 = no, we_step5 = no, err_step5 = yes, sel_step6 = 4, imm_step6 = no, we_step6 = yes, sel_step7 = 0, imm_step7 = no, we_step7 = no, err_step7 = yes, sel_step8 = 0, imm_step8 = yes, we_step8 = yes, sel_step9 = 0, imm_step9 = no, we_step9 = no, err_step9 = yes, sel_step10 = 3, imm_step10 = no, we_step10 = yes, sel_step11 = 0, imm_step11 = no, we_step11 = no, err_step11 = yes

Every second step is a reserved opcode. Each gives all zeros and err = 1, whatever the instruction before it set.

Example 3

Unlisted Opcodes with En at 0
Input
AND, en=0 op 5, ANDI, en=0 op 9, en=0 op 15, op 15, en=0 AND, CMPI, en=0 CMPI, en=0 op 14, op 14, ADD
Output
sel_step0 = 2, imm_step0 = no, we_step0 = yes, sel_step1 = 0, imm_step1 = no, we_step1 = no, sel_step2 = 2, imm_step2 = yes, we_step2 = yes, sel_step3 = 0, imm_step3 = no, we_step3 = no, sel_step4 = 0, imm_step4 = no, we_step4 = no, sel_step5 = 0, imm_step5 = no, we_step5 = no, err_step5 = yes, sel_step6 = 0, imm_step6 = no, we_step6 = no, sel_step7 = 1, imm_step7 = yes, we_step7 = no, sel_step8 = 0, imm_step8 = no, we_step8 = no, sel_step9 = 0, imm_step9 = no, we_step9 = no, sel_step10 = 0, imm_step10 = no, we_step10 = no, err_step10 = yes, sel_step11 = 0, imm_step11 = no, we_step11 = yes

With en at 0 a reserved opcode is not an error: the control word and err are all 0. The same opcode with en at 1 raises err.

Constraints and Contract

  • en and op are known 0/1 values. Each step is held one nanosecond and the outputs are read at its end.
  • Keep the module name and the ports. Every output must be a known 0 or 1 at every step.

Hints

Hint 1

Three questions decide the style. What must a reserved opcode give? Who must be told? May the synthesizer choose?

Hint 2

The brief answers all three: a value you are given, an err output, and no freedom. Which of the five styles states a value?

Hint 3

Give every output its "do nothing" value first. Then let each instruction change only the bits that differ, and let the default item raise err.

What the grader checks: Six directed and twelve seeded scripts apply twelve steps of en and op each, one per nanosecond. The control word after every step is compared with an independent model with no memory. Passing shows the decoder follows the brief on these scripts; the synthesis check adds the latch count.

The submitted design must synthesize with 0 latches and no combinational loop. Counts come from the pinned open-source synthesis flow. They are proxies for logic size and depth, not physical area or timing.

18 checks on Icarus Verilog + Yosys · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain public samples only. A passing result establishes the tested cases, not a proof for all possible inputs.

See all 2 steps and the final capstone

Report a problem with this page

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

Every Instruction

Input
ADD, SUB, AND, OR, XOR, ADDI, ANDI, CMP, CMPI, XOR, CMPI, ADD
Expected output
sel_step0 = 0, imm_step0 = no, we_step0 = yes, sel_step1 = 1, imm_step1 = no, we_step1 = yes, sel_step2 = 2, imm_step2 = no, we_step2 = yes, sel_step3 = 3, imm_step3 = no, we_step3 = yes, sel_step4 = 4, imm_step4 = no, we_step4 = yes, sel_step5 = 0, imm_step5 = yes, we_step5 = yes, sel_step6 = 2, imm_step6 = yes, we_step6 = yes, sel_step7 = 1, imm_step7 = no, we_step7 = no, sel_step8 = 1, imm_step8 = yes, we_step8 = no, sel_step9 = 4, imm_step9 = no, we_step9 = yes, sel_step10 = 1, imm_step10 = yes, we_step10 = no, sel_step11 = 0, imm_step11 = no, we_step11 = yes

Each of the nine opcodes gives its row of the table, and err stays 0.

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

Icarus Verilog + Yosys · server