Question: Hello, I'm trying to convert the C code below to MIPS. I'm stuck getting an error on line 40. Please fix this for me and

Hello, I'm trying to convert the C code below to MIPS. I'm stuck getting an error on line 40. Please fix this for me and tell me what is wrong (keep in mind i'm very new to MIPS)

C:

int main(void) {

int var1[4] ={7, 18, 11, 3};

int var2[4]= {12, 14, 7, 18};

int result[4]={0};

for (int i=0 ; i< 4; i++)

result[i] = var1[i] - var2[i]; }

MIPS:

.data var1: .word 7, 18, 11, 3 var2: .word 12, 14, 7, 18 result: .space 16

myStr: .asciiz, "Result = "

.text main:

add $t6, $zero, $zero #incrementer to avoid infinite loop

loop: la $t0, var1 #put address of array 1 in $t0 la $t1, var2 #put address of array 2 in $t1 la $t7, result #put address of result in $t7

add $t0, $t0, $t6 add $t1, $t1, $t6 add $t7, $t7, $t6

lw $t2, 0($t0) lw $t3, 0($t1)

sub $t4, $t2, $t3

sw $t4, 0($t7) # store result

addi $t5, $zero, 16 #make register for bne

addi $t6, $t6, 4 #incrementor

bne $t6,$t5,loop

li $v0, 4 la $a0, myStr #print string syscall

li $v0, 4 la $a0, $t7 syscall

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!