What you practice
Opcode and funct field decode (1.3). Extract opcode, funct3, and register fields from a 32-bit RISC-V instruction word using bit-slicing. It is in Opcode / funct decode — Part 1 · Fetch & Decode of the RISC-V RV32I Core Masterclass.
The RV32I core is Verilog you simulate in the browser IDE. Verilator runs the program; the waveform shows PC, the instruction, and the register write.
What you will learn
Today you will split a 32-bit RISC-V instruction word into its component fields. You will extract the opcode, funct3, funct7, and register numbers. This decoding is the first step in any RISC-V processor pipeline.
Learning objectives
- Extract opcode, funct3, and funct7 fields from an instruction word.
- Map register indices (rd, rs1, rs2) to their bit positions.
- Understand how the decoder drives control signals based on the opcode.
Theory
The RISC-V instruction format places fields at fixed bit positions. The opcode is always in the lowest 7 bits. The funct3 field sits in bits 14 through 12. The funct7 field occupies the highest 7 bits. Register destinations and sources follow immediately after the opcode. The rd field is in bits 11 through 7. The rs1 field is in bits 19 through 15. The rs2 field is in bits 24 through 20. The decoder uses these slices to identify the instruction type. It then sets control signals like regwrite and alu_op. This logic allows the rest of the CPU to know what operation to perform.
| Field | Bit Range | Description |
|---|---|---|
| opcode | [6:0] | Primary instruction type identifier |
| funct3 | [14:12] | Secondary opcode for ALU operations |
| funct7 | [31:25] | Tertiary opcode for ALU operations |
| rd | [11:7] | Destination register index |
| rs1 | [19:15] | First source register index |
| rs2 | [24:20] | Second source register index |
Practice
Open this chapter in RtlStudio and confirm the files appear in the Explore tree. Open student/rtl/ip/riscv/rv32i_decoder.sv in the editor. Locate the assign statements for opcode, rd, funct3, and rs1. Replace the __TODO__ placeholders with the correct bit-slice assignments from the instruction word inst. Save the file. Open student/tb/tb_top.sv and verify the testbench stimulus. Run Simulation from the left sidebar. Check the Log panel for the INFO: lines. Verify that the decoded values match the expected ADD instruction fields.
Summary
You practiced extracting specific bit fields from a 32-bit RISC-V instruction word to identify the opcode, funct3, funct7, and register indices. By implementing these bit-slice assignments in the decoder module, you learned how hardware determines the operation type and operands. The testbench validated your design by confirming that the decoded control signals matched the expected values for an ADD instruction.
© 2026 RtlStudio. Licensed under CC BY-NC-ND 4.0. Commercial use and modifications by third parties are not permitted.
Run it in the Verilog IDE
- Open the RV32I lesson in the IDE. Fetch, decode, and execute are source you can simulate.
- Run Verilator and watch PC, the instruction, and the register write on the waveform.
- Treat a program printout as done only after the ISA step this lesson names matches the wave.
- Change the RTL in the editor, rerun Verilator, and read the waveform again in the same tab.
The lesson is done when the simulation matches Opcode and funct field decode. Change the source, run the Verilog simulator again, and read the waveform without leaving the IDE. Simulation guide · Yosys guide.