Assembly can be a tough language to wrap one’s head around. It’s nitty, it’s gritty, and can be tricky to debug. The Microprocessor without Interlocked Pipelined Stages (MIPS) architecture is a simplified language that many universities use as an introduction to assembly.
While MIPS is considered a Reduced Instruction Set Computer (RISC) it can still be difficult to get familiarized with. Two of the basic operations available to programmers are the Store Word (SW) and Load Word (LW) commands. These commands are used to retrieve (load) and save (store) values from specified memory locations.
Store Word (SW)
The MIPS SW command has the following instruction signature: sw, $source, offset($destination)
where:
sw
is the command;$destination
is the register in which to save the value;offset
is the memory offset;$source
is the base address.
This command instructs the CPU to take whatever value is stored at memory location $source
and copy it to the memory location at $destination
.
TL;DR – sw
gets a value from a register and puts into memory
Load Word (LW)
The MIPS LW command has the following signature: lw, $destination, offset($source)
where
lw
is the command;$destination
is the register to which the value is to be stored;offset
is the memory offset;$source
is the base address from which data is retrieved.
This command instructs the CPU to take whatever value is held in the $source
register and save it into memory at the $destination
address.
TL;DR – lw
gets a value from memory and puts into a register
Summary
MIPS is a great language to learn the basics of assembly programming. The MIPS32 architecture helps expose a RISC set of instructions in a reduced memory setting which helps simplify things further. Basically, one wrangles 32-bit memory addresses during debugging rather than 64-bit addresses.
The sw
and lw
commands in MIPS are essential to loading and saving values from registers and memory locations. Understanding the fundamental actions of these commands can help pave the way to basic operations such as loading values into arrays, copying arrays, and preparing registers for procedure calls.