MIPS Store Word (sw) vs. Load Word (lw)

mips store word vs load word

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)

mips store word illustration
In this MIPS sw example, the sw command copies a register value into a memory location

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;DRsw gets a value from a register and puts into memory

Load Word (LW)

mips load word definition infographic
In this MIPS lw example, the lw command is loading the value at memory location $sp into register $s0

The MIPS LW command has the following signature: lw, $destination, offset($source) where

  • lw is the command;
  • $destinationis 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;DRlw 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.

Zαck West
Full-Stack Software Engineer with 10+ years of experience. Expertise in developing distributed systems, implementing object-oriented models with a focus on semantic clarity, driving development with TDD, enhancing interfaces through thoughtful visual design, and developing deep learning agents.