ISA & Assembly
What does the RISC-V auipc instruction (add upper immediate to PC) do?
- AStores the PC value directly to memory
- BAdds the 20-bit immediate shifted left by 12 bits to its own address (PC) and puts the result in a register
- 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.