In MIPS assembly language, Memory Operand Load Word (lw) and Store Word (sw) are fundamental instructions used for accessing data in memory. These instructions are essential for moving data between the CPU's registers and the main memory.
Load Word (lw):
The lw instruction is used to load a 32-bit word from memory into a register. Its syntax is:
wasm
lw $destination, offset($base)
Where:
$destination is the destination register where the loaded word will be stored.
offset is the displacement or offset from the base address.
$base is the base register containing the base address of the memory location.
The lw instruction calculates the effective memory address by adding the offset to the base address. It then fetches the word stored at that memory address and loads it into the destination register.
Example:
assembly
lw $t0, 32($s1) # Load the word at memory location (base address in $s1 + offset 32) into register $t0
Store Word (sw):
The sw instruction is used to store a 32-bit word from a register into memory. Its syntax is:
wasm
sw $source, offset($base)
Where:
$source is the source register containing the data to be stored.
offset is the displacement or offset from the base address.
$base is the base register containing the base address of the memory location.
The sw instruction calculates the effective memory address by adding the offset to the base address. It then stores the word from the source register into the memory location pointed to by the effective address.
Example:
assembly
sw $t0, 16($s2) # Store the word from register $t0 into memory location (base address in $s2 + offset 16)
Both lw and sw instructions are fundamental for manipulating data stored in memory in MIPS assembly language, facilitating the exchange of data between CPU registers and memory locations.
Негізгі бет Memory Operand Load Word & Store Word in MIPS Assembly Language - Class 2
Пікірлер