Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the following C code, which adds d to first 100 elements of array B and

ID: 3881412 • Letter: C

Question

Consider the following C code, which adds d to first 100 elements of array B and stores the result in array A. Both A and B are arrays of 64-bit integers, and d is a 64-bit integer. Assume A, B, and d are stored in memory. The address of d is 5000. The address of A and B are in R1 and R2 respectively. Variable i is kept in a register for (1-0; i 100; i ++) Implement the loop with ten (10) MIPS64 instructions. What is the size (in bytes) of your code? What is the total number of instructions that would be executed? What is the total number of data memory accesses? Hints MIPS64 instructions can be found in Figure A.26 on page A-40. Load d once before the loop. Increment i by 8 in each iteration. It can also be used as offset for accessing A and B

Explanation / Answer

main: li $t0, 0 # clear register $t0 to zero li $t4, 0 # clear register $t4 to zero loop: add $t0, $t0, 2 # generating even numbers in register $t0 add $t4, $t4, $t0 # compute the sume bne $t0, 100, loop # if t0 reached 100 then go to loop. b endloop # branch to endloop endloop: li $v0, 10 # terminate program run and syscall # Exit

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote