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

More ISA & Assembly questions

  1. 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?
  2. How do RISC-V and x86 differ in their mechanism for conditional branches?
  3. What does the RISC-V instruction "slt t0, a0, a1" do?
  4. When the RISC-V code above finishes, what is the value in t0?
  5. 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?