ISA & Assembly
In the RISC-V conditional branch "beq a0, a1, label", how is the target address of label encoded?
- AThe full 32-bit target address is held in the instruction
- BAs a distance from the address (PC) of the branch instruction itself, held in the instruction
- CThe target address must be placed in register a1 beforehand
Show answer and explanation
Answer: B. As a distance from the address (PC) of the branch instruction itself, held in the instruction
RISC-V branches encode the target as a signed distance in bytes from the address (PC) of the current instruction. This is called PC-relative addressing. Branch targets are usually nearby, so a short distance suffices and fits within the 32-bit instruction. And because the distance stays the same if the whole program is placed at another address, the code works without being rewritten.
- A. A 32-bit address cannot fit in a 32-bit instruction.
- B. Correct. This is PC-relative addressing.
- C. a1 is one of the values compared, not an address.