Question

3. Consider the following MIPS loop: LOOP: Comment slt $t2, 0, Sti beg $t2, 0, exit addi $t1, $t1,-1 addi Sal, $31, 2 TOOP ex
please explain fully
0 0
Add a comment Improve this question Transcribed image text
Answer #1

a)

LOOP:

Comments
slt $t2,0,$t1 if 0 is less than $t1, set $t2=1 otherwise $t2=0
beq $t2,0,exit if two are equal ie. if 0==$t2 then branch to target i.e. exit
addi $t1,$t1,-1 means $t1=$t1-1 i.e. adding sign extended immediate value
addi $s1,$s1,2 means $s1=$s1+2 i.e. adding sign extended immediate value
j Loop means goto Loop until exit branch executed
exit: another branch exit which comes when $t2==0

b) Equivalent C code-

Let take $t2 as j, $t1 as i and $s1 as a.

#include <stdio.h>

int main()
{
    int j,i=2;
    int a=0;
    do 
    {
        if(0<i)
        {
            j=1;
        }
        else{j=0;}
        i=i-1;
        a=a+2;
    }while(j!=0);
    printf("%d ", a);
    return 0;
}

c)

Dry run is shown below-

i a j
2 0 1
1 2 1
0 4 1
0 6 0

The value of a=6 when i=2 and a=0 and execution of code as shown in the screenshot below.

Run Debug Stop Share Save {} Beautify Language C main.c 8 9 #include <stdio.h> 10 11 int main() 12 { 13 int j,i=2; 14 int a=0

Add a comment
Know the answer?
Add Answer to:
please explain fully 3. Consider the following MIPS loop: LOOP: Comment slt $t2, 0, Sti beg...
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
  • 1. (15 pts) For the following C statement, what is the corresponding MIPS assembly code? Assume...

    1. (15 pts) For the following C statement, what is the corresponding MIPS assembly code? Assume f, g, h correspond to $80, $s1, and $s2, respectively. f=g+(h-5) 2. (15 pts) For the following pseudo-MIPS assembly instructions, what is the corresponding C code? add f, g, h add f,i, f 3. (30 pts) Provide the instruction type, assembly language instruction, and binary representation of the instruction described by the following MIPS fields: a. op = 0, rs = 18, rt=9, rd...

  • 2. The table below holds MIPS assembly code fragments with different branch instructions LOOP addi $s2....

    2. The table below holds MIPS assembly code fragments with different branch instructions LOOP addi $s2. $s2. 2 subi $t1. st1. 1 bne t1. 0. LOOP DONE: LOOP: it st2. $0. stl beq t2. 0. DONE addi $s2. Ss2. 2 LOOP DONE: For the loops written in MIPS assembly in the above table, assume that the register Şt1 is initialized to the value of 10. What is the value in register $s2 assuming that $s2 initially has a value of...

  • 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.

  • Consider the following MIPS code: add $t3,$t2,$t1 lw $t4,0($t3) sw $t7,0($t3) add $t6,$t2,$t8 addi $t3,$t5,4 (a)...

    Consider the following MIPS code: add $t3,$t2,$t1 lw $t4,0($t3) sw $t7,0($t3) add $t6,$t2,$t8 addi $t3,$t5,4 (a) Draw a general pipeline diagram from CC1 to CC5 (b) Can you identify the type of hazard in pipeline for executing the code? (c) What is the solution to the hazard? If NOP (noop or bubbles) have to be inserted to avoid hazard, where will you put them? (d) Put the code into the MIPS simulator and observe your findings. You may want to...

  • 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

  • Please comment the MIPS code to help me understand. Here is what the code accomplishes. Here...

    Please comment the MIPS code to help me understand. Here is what the code accomplishes. Here is the code, partially commented. .data Matrix: .word 41,45,5, 34,8, 15,16,23,44,48,12,32,18,47,22,8,22 .word 46,40,42,33,13,38,27,6, 29,25,18,40,47,22,26,14,3 .word 7, 48,35,9, 43,38,9, 49,28,25,42,5, 44,10,5, 38,14 .word 46,33,16,6, 13,20,31,1, 8, 17,1, 47,28,46,14,28,7 .word 32,2, 48,25,41,29,14,39,43,46,3, 39,32,49,41,28,46 .word 5, 43,2, 48,13,4, 33,41,32,19,9, 25,30,22,2, 9, 40 .word 14,47,22,18,47,3, 35,44,18,6, 33,22,11,6, 47,50,4 .word 28,34,20,30,18,27,38,5, 26,40,37,23,16,13,37,8,7 .word 48,38,39,12,10,39,23,20,21,20,33,16,24,21,25,3,46 .word 49,38,40,38,13,47,5, 13,4, 13,23,26,12,30,29,29, 3 .word 8, 20,10,13,31,7, 12,41,12,21,28,26,43,14,35,10,19 .word 49,33,25,26,24,29,46,22,7, 5, 15,41,10,31,19,41,27 .word 48,9,...

  • 4) Consider the following assembly language code: INSTRUCTIONS T01 T02 T03 T04 T05 T06 T07 T08...

    4) Consider the following assembly language code: INSTRUCTIONS T01 T02 T03 T04 T05 T06 T07 T08 T09 T10 T11 T12 T13 T14 (as a table) Loop: sll $t1, $s3, 2 add $t1, $t1, $s6 lw $t0, 0($t1) beq $t0, $s5, Exit addi $s3, $s3, 1 j Loop Exit: Use a pipeline with forwarding, hazard detection, and 1 delay slot for branches. The pipeline is the typical 5-stage IF, ID, EX, MEM, WB MIPS design. For the above code, complete the...

  • code: 3. (20 pts.) Consider the following fragment of for (i-0; i<=100; i-i++) { a [i]...

    code: 3. (20 pts.) Consider the following fragment of for (i-0; i<=100; i-i++) { a [i] = b[i] + c; Assume that a and b are arrays of words and that the base address of a is in Sao and the base address of b is in Sal. Register St0 is associated with variable i and register $so with the value c. You may also assume that any address constants you need are available to be loaded from memory. Make...

  • 5. Consider the SPIM code below. globl main .text main: ori $t1, $0, 10 ori $t2,...

    5. Consider the SPIM code below. globl main .text main: ori $t1, $0, 10 ori $t2, $0, 11 add $t3, $t1,$t2 move $t4, $t3 The following image shows a screen shot of QtSPIM page when this program is loaded, and executed in step-by step fashion. Current instruction is highlighted. Data Text x Text Regs Int Regs [16] Int Regs [16] PC = 400028 EPC 0 Cause = 0 BadAddr = 0 Status = 3000ff10 HI LO = 0 = 0...

  • Ch04.2. [3 points] Consider the following assembly language code: I0: ADD R4 R1RO I1: SUB R9R3 R4...

    Ch04.2. [3 points] Consider the following assembly language code: I0: ADD R4 R1RO I1: SUB R9R3 R4; I2: ADD R4 - R5+R6 I3: LDW R2MEMIR3100]; 14: LDW R2 = MEM [R2 + 0]; 15: STW MEM [R4 + 100] = R3 ; I6: AND R2R2 & R1; 17: BEQ R9R1, Target; I8: AND R9 R9&R1 Consider a pipeline with forwarding, hazard detection, and 1 delay slot for branches. The pipeline is the typical 5-stage IF, ID, EX, MEM, WB MIPS...

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