210k views
3 votes
Given a high-level code you should be able to write the corresponding MIPS assembly code. Simple loop in C; A[ ] is an array of ints do { g = g + A[i]; i = i + j; while (i != h) } Rewrite this as: Loop: g = g + A[i]; i = i + j; if (i != h) goto Loop; Using the mapping: g: $s1, h: $s2, i: $s3, j: $s4, base of A: $s5; write the corresponding assembly instructions

User Skquark
by
4.8k points

1 Answer

0 votes

Answer:

Step-by-step explanation:

The code for the given problem is written below

.data

A : .word 1 2 3 4 5 6 7 8 9 10

.text

la $s5,A

li $s1,0 # load g

li $s2,10 # load h

li $s3,0 # load i

li $s4,1 # load j

loop:

mul $s6,$s3,4

add $s6,$s6,$s5 #address of A[i]

lw $s6,($s6) #get value of A[i] in s3

add $s1,$s1,$s6 #g = g+A[i]

add $s3,$s3,$s4 # i = i+j

bne $s3,$s2,loop #if i!=h jump to loop

User CSRedRat
by
4.8k points