Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Translating single C line to MIPS Assembly

Tags:

c

assembly

mips

I am taking a university course in computer architecture so I am new to assembly language. My question is, how do I translate the following code from C to MIPS assembly language without using pseudoinstructions?

B [8] = A [i-j]

i and j are assigned to registers $s3 and $s4 and the base address of A and B are in registers $s6 and $s7. So far I have:

sub $t0, $s3, $s4
sll $t0, $t0, 2
lw $t1, $t0($s6)   #Is this line allright?
add $s5, $t1, $zero
sw $s5, 32($s7)

I'm not sure about using register $t0 as an offset to address memory in the third line. Thanks in advance.

like image 611
Carlos Barreto Avatar asked Oct 12 '13 00:10

Carlos Barreto


1 Answers

No. Instead calculate the address needed by adding $t0 to $s6.

sub $t0, $s3, $s4
sll $t0, $t0, 2
add $t0, $t0, $s6
lw  $t1, 0($t0)
sw  $t1, 32($s7)
like image 64
Konrad Lindenbach Avatar answered Nov 07 '22 05:11

Konrad Lindenbach