Question
Consider the following fragment of C code: for (i=0; i
Consider the following fragment of C code: for (i=0; i<=10; i++) { a[i] = b[i] + C; } Assume that a and b are arrays of words and the base address of a is in $a0 and the base address of b is in $a1. Register $t0 holds the variable i and register $s0 the constant C. Write the code for this fragment in MIPS
Would this be a valid answer? If it's incorrect can someone please explain why. Thank you
add $t0, $zero, 0 # initialize i = 0 ori $t4, $zero, 404 # initialize t4 to set number of bytes (101 * 4)
Loop:
add $t1, $a1, $t0 # $t1 = address of b[i] lw $t2, 0($t1) # $t2 = b[i] add $t2, $t2, $s0 # $t2 = b[i] + c add $t3, $a0, $t0 # $t3 = address of a[i] sw $t2, 0($t3) # a[i] = b[i] + c addi $t0, $t0, 4 # i = i + 4 bne $t4, $zero, Loop # goto Loop if i <= 404
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started