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 -2^11 = -2048 to 2^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.
Practice this topic Back to topic

More ISA & Assembly questions

  1. In RISC-V, what is the usual way to put a 32-bit constant that does not fit in a 12-bit immediate (e.g. 0x12345678) into a register?
  2. To build the constant 0x12345FFF in RISC-V with lui and addi, which pair is correct?
  3. What does the RISC-V auipc instruction (add upper immediate to PC) do?
  4. On RISC-V RV32I, what 32-bit value is in t0 after "addi t0, zero, -1"?
  5. A byte in memory holds 0x80. Which pair correctly gives the 32-bit register value after loading it with RISC-V lb and with lbu?