# Question 2 for HW 3 use MPLAB IDE # Your solution should implement the following loop: # for (i = 0; i < X; i++) { # A = A + X; # B = B - X; # if (A == B) # break; ## break exits loop early # } .global main .data ### THESE VARIABLES ARE SIMPLY GIVEN VALUES TO START ### WITH--CHANGE THEIR VALUES AND VERIFY YOUR PROGRAM ### WORKS APPROPRIATELY IN ALL CASES A: .int 1 B: .int 100 X: .int 20 .text .set noreorder .ent main main: # Load variables into registers lw $t0, A lw $t1, B lw $t2, X # Implement loop described above # Make sure final values for A and B are in memory # (but you don't necessarily have to update memory # in every loop iteration) # This code simply loops infinitely spin: j spin nop .end main
Tge required code is as below
.global main .data ### THESE VARIABLES ARE SIMPLY GIVEN VALUES TO START ### WITH--CHANGE THEIR VALUES AND VERIFY YOUR PROGRAM ### WORKS APPROPRIATELY IN ALL CASES A: .int 1 B: .int 100 X: .int 20 .text .set noreorder .ent main main: # Load variables into registers lw $t0, A lw $t1, B lw $t2, X move $t3,$0 #i =0 l1: bge $t3,$t2,done # for condition add $t0,$t0,$t2 # A =A+X sub $t1,$t1,$t2 #B =B-X beq $t0,$t1,done # if A=B exit for addi $t3,$t3,1 #i++ j l1 nop done:
# store variables from registers
sw $t0, A
sw $t1, B
sw $t2, X
.end main
Get Answers For Free
Most questions answered within 1 hours.