In MIPS assembly, write an assembly language version of the following C code segment:
int A[100], B[100];
for (i=1; i < 100; i++) {
A[i] = A[i-1] + B[i];
}
Answer:---------
An Assembly language version of the following C code
segment:
Given, C code segment:
int A[100], B[100];
for (i=1; i < 100; i++) {
A[i] = A[i-1] + B[i];
}
Corresponding Assembly Code:-----
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
Get Answers For Free
Most questions answered within 1 hours.