I am learning MIPS Assembly language and I was wondering how I can load values from an address. For example I want to store the memory address 0x10010000 in $t2. 0x10010000 has in it values 12,33,70,70(0x10010000 - 0x10010003). 0x10010004 would have something like F4,A6, 12,99((0x10010004 - 0x10010007).
I have this so far
add $t3, $t2, $zero
lw $t4, 0($t3)
add $t5, $t4, -6
sw $t5, 4($t2)
but don't know how I would "initialize" $t2
Put a label on your data, and use la $t2, labelName
.
Alternately you can load 0x10010000
into $t2
using lui
, which loads 16-bits worth of constant into the upper part of the registers — here you'd use lui $t2, 0x1001
.
If you needed non-zero for the low 16 bits (as in, say, for 0x10010400
), you finish them after the lui
with an ori
(e.g. ori $t2, $t2, 0x0400
).
Also, la
is a pseudo instruction. It will generally expand into two instructions, and, you'll be able to see that when you assemble your code (e.g. in MARS or QtSPIM).