Instruction Set Architecture (ISA)

load and store instructions

Load and store instructions are the processor's hands reaching between the fast workbench and the big storeroom. The registers are a tiny, blazing-fast workbench with only enough room for a few values; main memory is the huge but slower storeroom holding everything else. A load fetches a value out of memory and puts a copy on the workbench (into a register); a store takes a value from the workbench and writes it back into memory. Nothing useful gets computed in memory directly — you fetch, you work, you put back.

A load names a destination register and a memory address; a store names a source register and a memory address. The address is usually formed as a base register plus a small constant displacement, which is perfect for stepping through structures and arrays. In RISC-V, 'lw x5, 8(x10)' means: take the address in x10, add 8, read the word at that location in memory, and place it in x5. The matching 'sw x5, 8(x10)' writes the value in x5 back to that same memory location. The number in parentheses is the displacement; the register in parentheses is the base.

In a load-store architecture these are the only instructions allowed to touch memory — a deliberate, important restriction. Because memory is far slower than registers, isolating memory access into just two instruction types makes the rest of the machine simpler and faster, and it makes the cost of touching memory visible in the program. A common beginner surprise: a single line of source code like 'a = b + c' may compile into a load for b, a load for c, an add, and a store for a — four instructions, because the variables actually live in memory.

To increment a counter stored in memory at address x10: 'lw x5, 0(x10)' loads it into a register, 'addi x5, x5, 1' adds one in the register, 'sw x5, 0(x10)' stores the new value back. The add can only happen in a register, so a load and a store bracket it.

Load in, compute in a register, store back — the only way to update a value that lives in memory.

A load copies data; it does not move it. After a load, the value exists in both the register and memory until a store overwrites one of them. Forgetting to store a changed value back is a classic bug.

Also called
memory access instructionsloadstorelw / sw資料傳輸指令載入指令儲存指令