RTL Studio Open IDE

1.1 · RISC-V CLASS

Program counter with reset and PC+4

Implement a 32-bit Program Counter register with reset-to-zero and PC+4 increment logic, verifying the sequential address generation in a testbench.

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

What you practice

Program counter with reset and PC+4 (1.1). Implement a 32-bit Program Counter register with reset-to-zero and PC+4 increment logic, verifying the sequential address generation in a testbench. It is in PC, reset, PC+4 — 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 build the Program Counter (PC) register and its default increment logic for the RV32I ISA. This component is the heart of the fetch stage, determining which instruction executes next. Understanding how to reset and increment a register is fundamental to all CPU design.

Learning objectives

  • Implement a 32-bit register that resets to zero on active-low reset.
  • Connect the PC output to a combinational adder for PC+4 calculation.
  • Wire the PC+4 result back to the PC input as the next state.
  • Verify the PC sequence (0, 4, 8, 12) using a simple testbench.

Theory

The Program Counter holds the address of the current instruction. In the base RV32I ISA, instructions are 4 bytes wide, so the PC typically increments by 4 after each fetch. The PC must reset to a known starting address (usually 0) when the processor initializes. This is done using a synchronous reset with an asynchronous reset sensitivity list or a synchronous check inside the flip-flop. The next PC value is usually the current PC plus 4, unless a branch or jump occurs. For this lesson, we assume sequential execution, so next_pc = pc + 4.

ConceptDescription
Reset ValueThe initial value of the PC (typically 32'h0).
IncrementThe amount added to PC each cycle (typically 32'd4).
Next StateThe value loaded into PC on the next clock edge (pc + 4).

Practice

  1. Open RtlStudio and select this chapter in the Examples list.
  2. In the Explore panel, open student/rtl/ip/riscv/rv32i_pc.sv.
  3. Replace __TODO__[0] in the reset branch with 32'h0 to initialize the PC to zero.
  4. Replace __TODO__[1] in the normal operation branch with next_pc to load the next address.
  5. Open student/tb/tb_top.sv to review the testbench stimulus.
  6. Click Simulation in the sidebar and run the simulation.
  7. Check the Log panel for INFO: PASS.

Summary

You implemented a synchronous Program Counter register that initializes to zero on reset and increments by four on each clock cycle. This exercise demonstrated the fundamental fetch mechanism required for sequential instruction execution in an RV32I processor. The successful simulation confirmed that the PC correctly transitions through addresses 0, 4, 8, and C as expected.

© 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 Program counter with reset and PC+4. Change the source, run the Verilog simulator again, and read the waveform without leaving the IDE. Simulation guide · Yosys guide.