What you practice
JAL and JALR target calculation (2.5). Compute JAL and JALR jump targets and link addresses by connecting the immediate generator and implementing adder logic. It is in JAL & JALR target — Part 2 · Execute Path 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 learn how to compute the jump target address and the link address for JAL and JALR instructions. This is a critical part of the execute path in a RISC-V processor. You will connect the immediate generator to the adder logic. You will also implement the target masking for JALR.
Learning objectives
- Connect the
instport to the immediate generator module. - Compute the JAL target by adding the PC and the J-type immediate.
- Implement the JALR target calculation with proper bit masking.
- Verify the design using the provided testbench.
Theory
The JAL instruction performs an unconditional jump and link. It calculates the target address by adding the current PC to a 20-bit immediate value. The immediate is sign-extended and aligned to 2 bytes. The JALR instruction performs an indirect jump. It adds the base register rs1 to a 12-bit signed immediate. The least significant bit of the result is cleared to ensure alignment. The link address is always PC + 4 for both instructions.
| Instruction | Target Calculation | Link Address |
|---|---|---|
| JAL | pc + imm_j | pc + 4 |
| JALR | (rs1 + imm_i) & ~1 | pc + 4 |
The immediate generator rv32i_imm extracts the correct immediate field based on the instruction opcode and funct3/funct7 bits. You must connect the instruction word to this module to get the J-type immediate.
Practice
- Open
student/rtl/design.svin the Explore panel. - Connect the
instport ofu_immto the module'sinstinput. - Replace
__TODO__[0]in theu_imminstance with the correct signal names forinst,imm_i, andimm_j. - Implement the
jal_targetassignment usingpcandimm_j. - Open
student/tb/tb_top.svto see the test stimulus. - Run Simulation and check the Log panel.
Summary
You implemented the logic to compute jump targets for JAL and JALR instructions by connecting the immediate extraction module. You verified that the target addresses are correctly calculated using PC-relative offsets and register additions with LSB masking. The testbench confirmed that the link addresses are properly stored as PC plus four.
© 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 JAL and JALR target calculation. Change the source, run the Verilog simulator again, and read the waveform without leaving the IDE. Simulation guide · Yosys guide.