RTL Studio Open IDE

1.6 · RISC-V CLASS

Fetch and decode integration

Integrate PC, IMEM, decoder, and immediate generator into a fetch-decode stage.

Video coming soon. This lesson page stays at the same URL when the lecture publishes.

What you practice

Fetch and decode integration (1.6). Integrate PC, IMEM, decoder, and immediate generator into a fetch-decode stage. It is in Fetch-decode top — 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 integrate the program counter, instruction memory, decoder, and immediate generator into a single fetch-decode stage. This integration is essential for creating a functional instruction pipeline in a RISC-V core.

Learning objectives

  • Connect the rv32i_pc module to generate sequential instruction addresses.
  • Wire the instruction memory to fetch instructions based on the current PC.
  • Route fetched instructions to the decoder and immediate generator.
  • Verify the fetch-decode stage behavior using the provided testbench.

Theory

The fetch-decode stage is the entry point of the CPU pipeline. It retrieves the next instruction from memory and breaks it down into control signals and operands. The program counter (pc) holds the address of the current instruction. After fetching, the PC typically increments by four bytes to point to the next instruction. The instruction memory (imem) outputs the 32-bit instruction word at the address provided by the PC. The decoder (decoder) analyzes the opcode to determine the instruction type. The immediate generator (imm) extracts constant values embedded in the instruction format. These components must be wired together correctly for the CPU to execute code.

Practice

  1. Open RtlStudio and select this chapter in the Examples or Lecture list.
  2. Confirm that student/rtl/design.sv and student/tb/tb_top.sv appear in the Explore tree.
  3. Open student/rtl/design.sv in the editor.
  4. Locate the u_pc instance and replace the __TODO__[0] placeholders with the correct port connections.
  5. Ensure clk connects to clk, rst_n connects to rst_n, next_pc connects to next_pc, and pc connects to pc.
  6. Save the file.
  7. Open the Simulation panel in the sidebar and click Run.
  8. Read the Log panel to verify the output matches the expected results.

Summary

You successfully integrated the program counter, instruction memory, decoder, and immediate generator into a unified fetch-decode stage. This practice demonstrated how these components collaborate to retrieve instructions and prepare control signals for the pipeline. The key takeaway is understanding the front-end data flow that drives the RV32I execution core.

© 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

  1. Open the RV32I lesson in the IDE. Fetch, decode, and execute are source you can simulate.
  2. Run Verilator and watch PC, the instruction, and the register write on the waveform.
  3. Treat a program printout as done only after the ISA step this lesson names matches the wave.
  4. 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 Fetch and decode integration. Change the source, run the Verilog simulator again, and read the waveform without leaving the IDE. Simulation guide · Yosys guide.