Translate to MIPS

Posted by user2334400 on Stack Overflow See other posts from Stack Overflow or by user2334400
Published on 2013-11-04T02:41:15Z Indexed on 2013/11/04 3:54 UTC
Read the original article Hit count: 186

Filed under:
|

HELP Translate
A[i] = B[i-1] + B[i] + B[i+1] to MIPS

the address of array A is $s1 the address of array B is $s2 the value of i is $s3

lb $s1,0($s3)       # $s1=A[i]

lb $s2,0($s3)       # $s2=B[i]

sb $s2,0($s3)       # store s2

add $t0, $zero, $s2 #t0=B[i]

addi $s3,$s3,-1     #i=i-1

lb $s2 0($s3)       #$s2=B[i-1]

add $t1,$zero,$s2   #t1=B[i-1]

add $s1,$t0,$t1     #A[i]=B[i-1]+B[i]

addi $s3,$s3,2      #i+1

lb $s2,0($s3)       #s2=B[i+1]

add $t2,$zero,$s2   #t2=B[i+1]

add $s1,$s1,$t2     #A[i] = t1 + B[i+1]

sb $s1

I know this is kind of mess, but it's the best i can write

© Stack Overflow or respective owner

Related posts about assembly

Related posts about mips