Skip to main content
Engineering LibreTexts

6.3: Accessing Memory

  • Page ID
    27129
  • 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.

    • Was this article helpful?