Itamar
Itamar

Reputation: 534

Assembly .byte array

I've defined a byte array using

.data
letters  : .byte 0:26   

And i've got some questions : 1 ) Is the first cell in the array available for use, or its employed for other purpose? 2 ) How can I load the 6 ( for example ) cell of the array ?

I've thought about using :

la $t0, letters  # load the array address to $t0
addi $t0, $t0 , 6  # update $t0 in order to get the 6th cell
lb $t1, $t0        # load byte to $t1

Is this method valid or should I do it in other way?

Thanks in advance

Upvotes: 0

Views: 4477

Answers (2)

Jester
Jester

Reputation: 58762

Your code is almost valid, you are just missing a pair of parentheses for indirect addressing, like so:

lb $t1, ($t0) # load byte to $t1

Also, the address can include a constant offset, so in your case you don't have to add that separately:

lb $t1, 6($t0) # load byte to $t1

Note this only works for constants. If you want to index by another register you must do the addition like you did.

Vlad has already answered the other part.

Upvotes: 0

Vlad Krasnov
Vlad Krasnov

Reputation: 1027

1) Yes, it is available 2) Like in C the first cell has zero offset. So this way you will actually point to the seventh cell.

Upvotes: 1

Related Questions