ISA & Assembly

On RISC-V RV32I, what 32-bit value is in t0 after "addi t0, zero, -1"?

  1. A0xFFFFFFFF
  2. B0x00000FFF
  3. C0x80000001
Show answer and explanation

Answer: A. 0xFFFFFFFF

The immediate -1 is 0xFFF in 12 bits. addi sign-extends it to 32 bits, copying the top bit of 1 into every higher bit, giving 0xFFFFFFFF, which is -1 in two's complement. Thanks to sign extension, adding a negative immediate performs subtraction. Filling the upper bits with zeros would give 0x00000FFF = 4095, a different meaning.

  • A. Correct. -1 is sign-extended to all ones.
  • B. That is the value if zero-filled instead of sign-extended.
  • C. That is -1 in sign-magnitude, not two's complement.