I'm trying to load a byte from a word saved in data:
.data
number:
.word w1
part of the .text:
stringlength:
li $t2, 10
li $t1, -1
la $a0, number
loop:
addiu $t1, $t1, 1
lb $t0, $t1($a0)
bne $t0, $t2, loop
move $v0, $t1
jr $ra
*the code is not finished
My problem is with,
lb $t0, $t1($a0)
I'm trying to achieve a dynamic offset that will increment by 1, to check each byte in the string, to check wether it's equal to 10 (dec) or not.
QtSPIM raises an exception syntax error about this line,
What's the correct way of doing so?
The offset is a 16-bit signed integer contained in the instruction. The sum of the address in the base register with the (sign-extended) offset forms the memory address. Here is the load word instruction in assembly language: lw d,off(b) # $d <-- Word from memory address b+off # b is a register.
The MIPS ―load byte‖ instruction lb transfers one byte of data from main memory to a register.
The lb instruction loads the byte from memory into the low order eight bits of the register. These are bits 0-7 of the register. Then it copies bit 7 to bits 8-31 of the register (all bits to the left of bit 7).
The MIPS load byte instruction lb transfers one byte of data from main memory to a register. The store byte instruction sb transfers the lowest byte of data from a register into main memory. You can also load or store 32-bit quantities -- a complete word instead of just a byte -- with the lw and sw instructions.
There is no such addressing mode, you'll just have to calculate the address yourself by adding the offset, such as:
add $t0, $t1, $a0
lb $t0, ($t0)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With