Pergunta

I'm trying to learn MIPS and I've encountered the following example that shows how to convert a C code to MIPS:

I don't understand what is the purpose of the third MIPS line. Isn't the lw operand simply copies the value from t1 to t0 ?

Foi útil?

Solução

No, it reads a word from the address contained in $t1. Here's a commented version of the code:

Loop:
sll $t1, $s3, 2    # $t1 = i * sizeof(int)
add $t1, $t1, $s6  # $t1 += save  (== &save[i])
lw $t0, 0($t1)     # $t0 = *(&save[i])  (== save[i]) 
bne $t0,$s5, Exit  # if (save[i] != k) goto Exit
addi $s3, $s3, 1   # i += 1
j Loop             # repeat
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top