0

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

Jester
  • 56,577
  • 4
  • 81
  • 125
Itamar
  • 524
  • 1
  • 9
  • 21
  • What is the processor architecture you are targeting? Please add the appropriate tag next to 'assembly' tag. – nrz Jan 06 '13 at 13:35
  • Just FYI, `.byte 0:26` is *not* valid GAS syntax in general for GNU Binutils `as`. It's specific to the assembler in MARS or SPIM, I assume. – Peter Cordes Nov 15 '19 at 17:36

2 Answers2

1

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.

Vlad Krasnov
  • 1,027
  • 7
  • 12
0

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.

Jester
  • 56,577
  • 4
  • 81
  • 125