ISA & Assembly

The immediate of RISC-V addi is a 12-bit signed integer. What range can it represent?

  1. A0 to 4095
  2. B-2048 to 2047
  3. C-4096 to 4095
Show answer and explanation

Answer: B. -2048 to 2047

A 12-bit two's complement value ranges from−211=−2048-2^11 = -2048to211−1=20472^11 - 1 = 2047. The immediate is sign-extended to 32 bits (64 on RV64) before use, so negative numbers can be added directly. To use a constant beyond this range, several instructions are combined, for example setting the upper 20 bits with lui and then adding the lower 12 bits with addi.

  • A. That is the unsigned 12-bit range.
  • B. Correct. The 12-bit two's complement range.
  • C. That range needs 13 bits.