Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MIPS load byte (lb) with offset

Tags:

assembly

mips

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?

like image 886
zeako Avatar asked Nov 23 '12 19:11

zeako


People also ask

How do offsets work in MIPS?

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.

What does lb do in MIPS?

The MIPS ―load byte‖ instruction lb transfers one byte of data from main memory to a register.

What does lb do in assembly?

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).

How does SB work in MIPS?

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.


1 Answers

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)
like image 69
Jester Avatar answered Oct 11 '22 17:10

Jester