ISA & Assembly
What does the RISC-V instruction "lw t0, 8(sp)" do?
- AWrites the 4 bytes of t0 to the address sp + 8
- BReads 4 bytes from the address sp + 8 and puts them in t0
- CReads 4 bytes from the address sp × 8 and puts them in t0
Show answer and explanation
Answer: B. Reads 4 bytes from the address sp + 8 and puts them in t0
lw stands for load word and reads 32 bits (4 bytes) from memory. "8(sp)" means the address formed by adding 8 to sp as a base; this way of specifying an address is called base-plus-offset (register indirect with displacement). It is convenient for reaching stack variables or struct members at a fixed distance from a base. The opposite, writing a register to memory, is sw (store word).
- A. Writing is done with the sw instruction.
- B. Correct. It loads from base register plus offset.
- C. The offset is added, not multiplied.