Start New Discussion within our Software Development Community

So I am trying to reverse a string inputed by a user and I am getting an error on one line of my code the line is lw $t3, $t0($t1) #load value. Why can I not do this?

.data
prompt: .asciiz "Enter in a string: "
backwards: .asciiz "That string backwards is: "
newLine: .asciiz "\n"
.text
main:
    la  $a0, prompt #call opening prompt
    li  $v0, 4      #output string
    syscall
    li  $v0, 8      #read a string
    syscall
    la  $a0, newLine    #call opening prompt
    li  $v0, 4      #output string
    syscall
    #$a0 is the string $a1 is the length of the string
    move    $t0, $a0    #move a0 to t0
    move    $t1, $a1    #move a1 to t1
    li  $v0, 11     #code to print char
Loop:
    sub $t1, $t1, 1
    lw  $t3, $t0($t1)   #load value
    lb  $a0, ($t3)  #load the byte
    syscall         #print byte
    bnez    $a1, Loop


    li      $v0, 10              #terminating
    syscall 

Because MIPS is a RISC and there is no such instruction.

LW -- Load word

Description:
A word is loaded into a register from the specified address.
Operation:
$t = MEM[$s + offset]; advance_pc (4);
Syntax:
lw $t, offset($s)
Encoding:
1000 11ss ssst tttt iiii iiii iiii iiii

I guess the 'i's here are immediate constant bits.

You just have to do the adding first and use the result as indirect.
add $t4, $t0, $t1
lw $t3 ($t4)

This question has already been answered. Start a new discussion instead.