What you practice
Main control signal decoder (1.5). Implement the main control signal decoder for RV32I instructions to generate regwrite, alusrc, and other control signals. It is in Main control decoder — 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
You will implement the main control logic for an RV32I processor. This logic decodes the instruction opcode to generate signals like regwrite, alusrc, and memread. These signals dictate how the processor executes instructions.
Learning objectives
- Decode the instruction opcode to identify the instruction type.
- Assert
regwritefor instructions that update the register file. - Assert
alusrcfor instructions that use immediate values for the ALU. - Verify control signals using a testbench with multiple instruction types.
Theory
The control unit translates the instruction opcode into specific control signals. Each instruction type requires a unique combination of these signals. For example, load instructions must assert memread and regwrite. Store instructions must assert memwrite but not regwrite. The alusrc signal selects between register data and immediate values for the ALU input. The decoder uses a case statement to map opcodes to these signals. Default values are set to zero to ensure unused signals are deasserted. The unique case statement ensures only one instruction type is active at a time.
Practice
- Open RtlStudio and select this chapter.
- Navigate to
student/rtl/ip/riscv/rv32i_decoder.svin the Explore panel. - Locate the
__TODO__placeholders in thealways_combblock. - Implement the logic to assert control signals based on the opcode.
- Assert regwrite for instructions that write to the register file (e.g., ADD, ADDI, LW). - Assert alusrc for instructions that use immediate values for the ALU (e.g., ADDI, LW). - Assert memread for load instructions. - Assert memwrite for store instructions.
- Open
student/tb/tb_top.svin the Explore panel. - Run Simulation from the sidebar.
- Check the Log panel for
INFO: PASS.
Summary
You implemented the main control signal decoder by mapping RV32I opcodes to specific control signals like regwrite, alusrc, and memread. This practice reinforced how the CPU's brain directs data flow through the datapath for different instruction types. Successfully passing the simulation confirms your decoder correctly handles register writes, memory accesses, and branch logic.
© 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 Main control signal decoder. Change the source, run the Verilog simulator again, and read the waveform without leaving the IDE. Simulation guide · Yosys guide.