Search code examples
replacemipsxor

Place returned value from xor operation in the string on MIPS


I am trying to replace result in the string but I could not.

addu    $t1, $t1, -1
lb  $t7, ($t1)
addu    $t1, $t1, 2
lb  $t8, ($t1)
xor $t6, $t7, $t8
addu    $t1, $t1, -2

beq $t6, 0, add_zero
beq $t6, 1, add_one

add_zero:
la  $t6, 48
sb  $t6, ($t1)

j   fourth_phase

add_one:
la  $t6, 49
sb  $t6, ($t1)  
j   fourth_phase

I checked that t6 has true value.

t6 should be first element of t1 and t1[1] and t1[2] should be deleted.

When I execute this code I get this error.

Memory address out of bounds        

How can I do this?


Solution

  • I modified these parts

    la  $t6, 48
    sb  $t6, ($t1) 
    ...
    la  $t6, 49
    sb  $t6, ($t1) 
    

    like this

    addu    $t6, $t6, 48
    sb      $t6, ($t1)
    

    and problem solved.