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
  • 2. Translate the following code into MIPS code.         B [0] = 5; for (i =...

    2. Translate the following code into MIPS code.         B [0] = 5; for (i = 1 ; i < 50 ; i = i + 2) {                         B[i] =i + B[i-1]; } Assume the compiler associates the variable i to the register $t0. Also, assume B is an array of integers and its address is stored at register $s1.   

  • Write an equivalent MIPS code for the following C code. Assume that the base address of...

    Write an equivalent MIPS code for the following C code. Assume that the base address of an array A is stored in register 450. Variables x, i, j and h are stored in registers $t0,$t1, $t2 and $t3 respectively. do{ x = x + A[i]; i = i + j; } (while i != h); Make sure your MIPS code has sufficient comments.

  • Translate the following code into MIPS code. Test (int i, int j)                         {        &nbsp

    Translate the following code into MIPS code. Test (int i, int j)                         {                         int k;                         k = Double(i+1) + Double (j-10)                         return k;                         } Sub (int m)                         {                         int g;                         g = m + m;                         return g;                         } Assume the compiler associates the variable k to the register $s0. Assume the compiler associates the variable g to the register $t0.

  • Translate the following C code to MIPS assembly. Assume that the values of a, b, i,...

    Translate the following C code to MIPS assembly. Assume that the values of a, b, i, and j are in registers $s0, $s1, $t0, and $t1, respectively. Also assume that $s2 holds the base address of the array D. for (i = 0: i < a: i++) for (j = 0: j < b: j++) D[2 * j] = i + j;

  • Using beq only, not bge! Translate the following C code to MIPS assembly code. Use a...

    Using beq only, not bge! Translate the following C code to MIPS assembly code. Use a minimum number of instructions. Assume that the values of a, b, i, and j are in registers $s0, $s1, $t0, and $t1, respectively. Also, assume that register $s2 holds the base address of the integer array D. Comments are required. for(i=1; i<a; i++) for(j=1; j<b; j++) D[2*j] = i + j;

  • IN MIPS AND MUST RUN IN QTSPIM Translate the following C code to MIPS assembly code....

    IN MIPS AND MUST RUN IN QTSPIM Translate the following C code to MIPS assembly code. Use a minimum number of instructions. Assume that the values of a, b, i and j are stored in registers Ss0, Ss1, St0 and Stl, respectively. Also assume that register Ss2 holds the base address of the array D. for (i=0; i<a; itt) for (i-0j<b:jt+)

  • 7. Translate the following C code to MIPS assembly code. Use a minimum number of instructions....

    7. Translate the following C code to MIPS assembly code. Use a minimum number of instructions. Assume that the values of a,b, i and j are in registers Ss0, Ss1, St0, and St1, respectively. Also, assume that register SS2 holds the base address of the array D. for(i-0; i<a; i++) for(j=0 ; j<b; j++)

  • Translate each of the following pseudo-instructions into MIPS instructions. You should Produce a minimal sequence of...

    Translate each of the following pseudo-instructions into MIPS instructions. You should Produce a minimal sequence of MIPS instructions to accomplish the required computation. (8 Points) 1) bgt $t1, 100, Label # bgt means branch if greater than 2) ble $s2, 10, Next # ble means branch if less than or equal 3) ror $s0, $s4, 7 # ror means rotate right $s4 by 7 bits and store the result in $s0 4) neg $s5, $s4 # $s5 will have the...

  • Assignment 3 Translate the following MIPS code to C. Assume that the variables f, g, h,...

    Assignment 3 Translate the following MIPS code to C. Assume that the variables f, g, h, i and j are assigned to registers Ss0, Ss1, Ss2, Ss3 and Ss4, respectively. Assume that the base address of the arrays A and B are in registers Ss6 and $s7, respectively. addi St0, Ss6, 4 add $t1, $s6, $0 #register $0 always holds 320s sw St1, 0(Sto) add Ss0, St1, Sto

  • 2.9 5 $2.2, 2.3> Translate the following C code to MIPS. Assume that the variables f,...

    2.9 5 $2.2, 2.3> Translate the following C code to MIPS. Assume that the variables f, g, h, i, and j are assigned to registers $s0, $s1, $s2, $s3, and $s4, respectively. Assume that the base address of the arrays A and B are in registers $s6 and $s7, respectively. Assume that the elements of the arrays A and B are 4-byte words: fAlBg

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