la
pseudolyszt.net covers la and other RISC-V instructions in more detail.
Description
la loads the address of something into a register. That address is a memory location, and the value stored at that location is a separate thing. The name stands for load address.
When you reserve data in memory, you give it a name like arr or msg, which spares you from tracking raw address numbers. That name is a label, a readable substitute for a memory address. The next line loads the address marked by the label arr into t0. It supplies the location where the array starts and does not read the array's contents.
la t0, arr
The load and store instructions (lw, sw and the rest) take an address held in a register. Before you can read or write named data, its address must be in a register, and la places it there. Reading the value takes two instructions. la finds where the data is, and lw reads what is there.
The RISC-V manual describes auipc as the instruction for building pc-relative addresses. It states that an auipc followed by a load or store with a 12-bit offset can reach any 32-bit pc-relative data address.
An address and its contents differ in the same way a pointer and a value differ. After the address is in a register, you reach individual elements by adding offsets to it. The example loads the address of a piece of text into a0, which is what the print-string service requires. It must be told where the text is, and it reads the text from there. la is a pseudo-instruction that the assembler builds from a couple of real ones.
Expands to
auipc rd, hi(label) addi rd, rd, lo(label)
The assembler replaces this pseudo-instruction with the real instruction or instructions listed above.
Example
.data msg: .string "hi" .text la a0, msg # a0 = address of msg
