Reputation: 369
I have an array with .space 36, which contains 7 numbers and 8 letters. (structured like this: xxxxxx11x11x111)
I can succesfully load the first 6 characters, but I cant load the first (and the other) numbers.
I iterate trough the array like this:
#5th char: the last x before the first 1
la $t0, array
lb $a0, 5($t0)
move $t0, $a0
beq $t0, 'x', loop
This works properly, but if i write:
#6th position, the first number 1 of the sequence
la $t0, array
lw $a0, 6($t0)
move $t0, $a0
beq $t0, 1, loop
It doesnt work! (it doesnt make the right beq, even if the number is 1)
Why? Thanks :)
I instantiate the array in this way:
#Get the user input string and save it as an array
li $v0, 8
la $a0, array
li $a1, 36
syscall
Upvotes: 0
Views: 562
Reputation: 81
It may not be working because you are have an alignment error when executing the load word instruction. lw can only load the data from adresses that are multiples of 4 (0x1001000, 0x1001004, 0x1001008, 0x100100c, 0x1001010, etc.). lb (load byte) however does not have to worry about alignment because you are only loading a byte, not a word. This answer explains it in more detail:
Upvotes: 3