March 11

LW Mips: Load Word Opcode Example

0  comments

LW is a MIPS Assembly instruction(opcode), stand for Load word. Lw MIPS is used to load a word from memory into a register. The general form of LW(Load word) in MIPS Assembly is:

[thrive_highlight highlight=’#3d7ebf’ text=’light’]Lw d, off(base)[/thrive_highlight]

Characteristics of LW MIPS Instruction

Lw instruction includes:

  • LW to perform a load word instruction.
  • A destination register(d) where the word would be loaded.
  • An offset which is a 16-bit unsigned integer, necessary to make a memory address.
  • A base register. The offset and base register combine to give memory address.

MIPS Lw Program Example

See the below example to understand the use of load word instruction.

PROGRAM

.data
lwExample: .word 3,2,5,5,6

.text
li $t0,0

while:
bgt $t0,20,Exit
Add $t0,$t0,4

lw $a0,lwExample($t0)

li $v0,1
syscall
j while

Exit:
li $v0,10
syscall

EXPLANATION

In the above program, we described the use of LW(load word) in an array. We initialized an array(lwExample) and assigned five values of type word. In the main body of the program, we used a while loop to increment the index at each iteration. At each increment, we add 4 to index because each value is stored in 4 bytes. We used a lw instruction to retrieve values from each index of the array and print it.

 


Tags


You may also like