Skip to main content
Engineering LibreTexts

6.3: Accessing Memory

  • Page ID
    27129
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    All memory access in MIPS in done through some form of a load or store opertoar. These operators include loading/storing a: byte (lb, sb); half word (lh, sh); word (lw, sw); or double word (ld, sd)20. In this chapter only words of memory will be considered, so only the lw and sw will be documented.

    • lw operator, which has a number of pseudo operator formats, but only two format will be documented here. The first format is the only real format of this operator. In this format, an address is stored in Rs, and an offset from that address is stored in the Immediate value. The value of memory at [Rs + Immediate] is stored into Rt.

      format:

      lw Rt, Immediate(Rs)

      meaning:

      Rt <- Memory[Rs + Immediate]

      The second format of the lw is a pseudo operator that allows the address of a label to be stored in Rs and then the real lw operator is called to load the value.

      format:

      lw Rs, Label

      meaning:

      Rt <- Memory[Label]

      translation:

      lui Rs, 0x10010000

      lw Rt, offset(Rs) # offset is displacement of value

      # in the data segement

    • sw operator, which has a number of pseudo operator formats, but only two format will be documented here. The first format is the only real format of this operator. In this format, an address is stored in Rs, and an offset from that address is stored in the Immediate value. The value of Rt is stored in memory memory at [Rs + Immediate].

      format:

      lw Rt, Immediate(Rs)

      meaning:

      Memory [Rs + Immediate] <- Rt

      The second format of the sw is a pseudo operator that allows the address of a label to be stored in Rs and then the real lw operator is called to load the value.

      format:

      lw Rs, Label

      meaning:

      Memory[label] <- Rt

      translation:

      lui Rs, 0x10010000

      sw Rt, offset(Rs) # offset is displacement of value

      # in the data segement


    20 The la operator is not included here because it does not load a value from memory into a register. It is a pseudo operator which is short hand for taking the address of a label, and putting it in a register. It does not load memory values into a register.


    This page titled 6.3: Accessing Memory is shared under a CC BY 4.0 license and was authored, remixed, and/or curated by Charles W. Kann III.

    • Was this article helpful?