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.
Practice this topic Back to topic

More ISA & Assembly questions

  1. What does the RISC-V instruction "jal ra, func" do?
  2. Which real instruction executes the RISC-V pseudo-instruction "ret"?
  3. What is the main purpose of defining a calling convention?
  4. In the standard RISC-V calling convention, which registers pass integer arguments and return values?
  5. In the standard RISC-V calling convention, when calling a function with ten integer arguments, where are the ninth and tenth passed?