ISA & Assembly

What does the RISC-V auipc instruction (add upper immediate to PC) do?

  1. AStores the PC value directly to memory
  2. BAdds the 20-bit immediate shifted left by 12 bits to its own address (PC) and puts the result in a register
  3. CJumps unconditionally to the address given by the immediate, overwriting the PC
Show answer and explanation

Answer: B. Adds the 20-bit immediate shifted left by 12 bits to its own address (PC) and puts the result in a register

auipc simply puts PC + (immediate << 12) into a register. Following it with jalr or lw that add a low 12-bit offset lets code name a function or data item within about ±2 GiB of the current position as a distance from the PC. This allows position-independent code, which runs wherever it is loaded, to call distant functions and read global variables.

  • A. It does not store to memory.
  • B. Correct. It builds PC-relative addresses.
  • C. auipc itself does not jump.
Practice this topic Back to topic

More ISA & Assembly questions

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