next up previous
Next: Address Modes Up: Registers and MAL Previous: Registers

Load/Store Instructions

The MAL lw (load word) and sw (store word) instructions are used to move data between RAM and a register. The instruction
        lw      $8, B

moves a word from location B in RAM to register $8. The instruction

        sw      $10, A
moves a word from register $10 to memory location A.

To execute the SAL instruction

        add     A, B, C

requires the MAL instructions

        lw      $8, B   # load B into $8
        lw      $9, C   # load C into $9
        add     $10, $8, $9  # $10 = $8 + $9
        sw      $10, A  # store $10 in A

The general form of the load and store instructions is:

        lw      R, Address
        sw      R, Address
where R is a general register and Address is either a label or a base displacement address, as described in the next section. In the lw and sw instructions, Address must be a word address (a multiple of 4 bytes).

There are separate load and store instructions to manipulate bytes of data. The lb (load byte), lbu (load byte unsigned) and sb (store byte) instructions operate on single bytes. The form of these instructions is:

        lb      R, Address
        lbu     R, Address
        sb      R, Address
where R is a general register and Address is a label or base displacement address. The Address in this case is a byte address. The lb and lbu instructions move a byte from Address to the least-significant byte of register R.

The lb instruction extends the sign bit of the byte to fill the register. The lbu instruction fills bits 8-31 of the register with 0's.

The half-word load and store instructions operate on two bytes of data. The general form of these instructions is:

        lh      R, Address
        lhu     R, Address
        sh      R, Address
where R is a general register and Address is a byte address. These instructions are identical with the byte instructions, except that two bytes of data are moved.

Two additional load instructions do not move data from RAM. The li (load immediate) instruction is used to load a constant into a register. The general form is:

        li      R, Constant

The la (load address) instruction is similar to the SAL la instruction. In MAL, la is used to place the address of a label into a register:

        la      R, Label

The MAL load and store instructions are shown below:

tabular1405

Notes:

  1. R is the contents of a general register.
  2. Address can be a label or a base displacement expression.
  3. tex2html_wrap_inline3204 indicates concatenation of bit fields.
  4. Superscripts indicate repetitions of bit fields.
  5. Subscripts indicate bit positions (Little-Endian) of sub-field.


next up previous
Next: Address Modes Up: Registers and MAL Previous: Registers

CS 301 Class Account
Mon Sep 13 11:15:41 ADT 1999