Question

Translate the following code into MIPS code.         j=0; k=0; for (i = 1 ; i...

Translate the following code into MIPS code.
       

j=0;

k=0;

for (i = 1 ; i < 50 ; i = i + 2)

{

K=k+1;           

j = (i + j);

            B[k] = j;

}

Assume the compiler associates the variables i, j, and k to the registers $t0, $t1, and $t2 respectively. Also, assume B is an array of integers and its address is stored at register $s1.

PLEASE DO NOT COPY DOWN ANOTHER SOLUTION

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Screenshot

---------------------------

Program

#Main program
.text
#Initialize i,j,and k
addi $t1,$0,0        #j=0
addi $t2,$0,0        #k=0
addi $t0,$0,1        #i=1
#for loop
loop:
beq $t0,50,exit     #i<50
addi $t2,$t2,1      #k=k+1
add $s1,$s1,$t2    #for getting B[k]
add $t1,$t0,$t1     #j=i+j
sb $t1,($s1)      #B[k] = j
addi $t0,$t0,2     #i=i+2
j loop
#end of the program
exit:
li $v0,10
syscall

Add a comment
Know the answer?
Add Answer to:
Translate the following code into MIPS code.         j=0; k=0; for (i = 1 ; i...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT