Write the main decoder and the ALU decoder of a single-cycle core, for nine opcodes. Six rows are in the lesson. You work out three more from the datapath.
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
The lab of the lesson has a control table of six rows, and its ALU operation is given. A real core needs more. This one also runs jalr, lui and auipc, and it finds the ALU operation itself.
Write the block that makes every control signal from the instruction word. It has no clock. The bench feeds it real instruction words from an assembler.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
trial | 10 | input of each check |
Full specification
| Signal | Value | What the datapath does |
|---|---|---|
| alu_a_select | 0, 1, 2 | The first ALU operand is rs1_data, the PC, or zero. |
| alu_b_select | 0, 1 | The second ALU operand is rs2_data, or the immediate. |
| result_select | 0, 1, 2 | rd takes the ALU result, the loaded value, or the PC plus 4. |
| jump_register | 0, 1 | The target is the PC plus the immediate, or rs1_data plus the immediate. |
| reg_write, mem_read, mem_write, branch, jump | 0, 1 | As in the lesson. |
| Opcode | Instruction | What it does |
|---|---|---|
| 1100111 | jalr | The PC takes rs1_data plus the immediate. rd takes the PC plus 4. |
| 0110111 | lui | rd takes the immediate. The immediate generator has already put its 20 bits in the upper part. |
| 0010111 | auipc | rd takes the PC plus the immediate. |
| Operation | Value | Operation | Value |
|---|---|---|---|
| add | 0000 | xor | 0100 |
| sub | 1000 | srl | 0101 |
| sll | 0001 | sra | 1101 |
| slt | 0010 | or | 0110 |
| sltu | 0011 | and | 0111 |
How to read a result: a public case shows the outputs that the datapath uses for that word. A private case feeds many words of one kind, and all_match is 1 when every word was right.
Examples
Example 1
An Add- Input
the word 006283b3: add x7, x5, x6
- Output
reg_write = 1, mem_read = 0, mem_write = 0, branch = 0, jump = 0, alu_a_select = 0, alu_b_select = 0, alu_operation = 'b0000, result_select = 0
The row OP. The ALU adds two registers, and the result goes to rd. The output jump_register is not used and not shown.
Example 2
A Load- Input
the word 00052283: lw x5, 0(x10)
- Output
reg_write = 1, mem_read = 1, mem_write = 0, branch = 0, jump = 0, alu_a_select = 0, alu_b_select = 1, alu_operation = 'b0000, result_select = 1
The row LOAD. The ALU adds rs1_data and the immediate, the memory is read, and rd takes the loaded value.
Example 3
A Branch- Input
the word fe029ce3: bne x5, x0, 0x10, at address 18 in hex
- Output
reg_write = 0, mem_read = 0, mem_write = 0, branch = 1, jump = 0
The row BRANCH. Only the five enables matter here. The datapath does not use the ALU or the result select.
Constraints and Contract
- The outputs depend only on the word of the same moment. The bench waits 1 ns after it sets a word.
- The five enables are checked for every word: reg_write, mem_read, mem_write, branch and jump.
- For a word whose opcode is not one of the nine, all five enables are 0.
- An output that the datapath does not use for a word is not checked. For a branch, that is every output except the five enables.
- The bench feeds no word that has one of the nine opcodes and is not an instruction.
Hints
Hint 1
Write the six rows of the lesson first. For each new instruction, ask where its operands come from and where its result goes.
Hint 2
lui has no first operand. Which value of alu_a_select makes the ALU pass the immediate on unchanged?
Hint 3
In which words is bit 30 a part of the immediate? There it must not change the operation.
What the grader checks: All ten operations on two registers. Six kinds of arithmetic with an immediate, each with immediates that have bit 10 set and clear, and the three shifts. Loads and stores of every size, and the six branches. Then jal, jalr, lui and auipc with bit 30 at both values, and 16 words with other opcodes.
11 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