In MIPS assembly write an assembly language version of the f
In MIPS assembly, write an assembly language version of the following C code:
int A[100], B[100];
for (i=1; i < 100; i++) {
A[i] = A[i-1] + B[i];
}
Solution
The MIPS assembly sequence is as follows:
li $t0, 1 # Starting index of i
li $t5, 100 # Loop bound
loop:
lw $t1, 0($a1) # Load A[i-1]
lw $t2, 4($a2) # Load B[i]
add $t3, $t1, $t2 # A[i-1] + B[i]
sw $t3, 4($a1) # A[i] = A[i-1] + B[i]
addi $a1, 4 # Go to i+1
addi $a2, 4 # Go to i+1
addi $t0, 1 # Increment index variable
bne $t0, $t5, loop # Compare with Loop Bound
halt:
nop
![In MIPS assembly, write an assembly language version of the following C code: int A[100], B[100]; for (i=1; i < 100; i++) { A[i] = A[i-1] + B[i]; }SolutionTh In MIPS assembly, write an assembly language version of the following C code: int A[100], B[100]; for (i=1; i < 100; i++) { A[i] = A[i-1] + B[i]; }SolutionTh](/WebImages/22/in-mips-assembly-write-an-assembly-language-version-of-the-f-1050325-1761546991-0.webp)