ISA & Assembly

RISC-V conditional branches (B-type) encode the distance as a 13-bit signed byte offset whose lowest bit is always 0 and not stored. Roughly what range can a branch reach directly?

  1. AAbout 4 KiB before or after the branch
  2. BAbout 1 MiB before or after the branch
  3. CAnywhere in memory
Show answer and explanation

Answer: A. About 4 KiB before or after the branch

A 13-bit signed value covers -4096 to +4095, but instructions are aligned on 2-byte boundaries, so the lowest bit is always 0 and the range is -4096 to +4094 bytes. Omitting that bit doubles the reach for the same field size. For a more distant target, the assembler rewrites the code as a short branch on the inverted condition that skips over a jal, which reaches about ±1 MiB.

  • A. Correct. -4096 to +4094 bytes.
  • B. About 1 MiB is the reach of jal (21 bits).
  • C. A limited number of bits cannot cover all of memory.