Question

(Computer Architecture MIPS Assembly) Using minimum amount of nops - rewrite the code segment below so...

(Computer Architecture MIPS Assembly)

Using minimum amount of nops - rewrite the code segment below so it doesn't cause any hazards.
You may not reorder the original instructions, just insert nop where needed.

add $3, $2, $3
lw $4, 100($3)
sub $7, $6, $2
xor $6, $4, $3
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution:

add $3, $2, $3

nops

nops

lw $4, 100($3)

sub $7, $6, $2

nops

xor $6, $4, $3

Explanation:

First two nops:

The new value of register 3 doesn’t reach the register file until the WB stage of the add instruction, i.e. cycle 5. But the lw instruction needs this value in its ID stage, when it reads register 3. To delay the ID stage of the lw until cycle 5, we need to insert 2 no-ops.

Third nops:

The new value of register 4 doesn’t reach the register file until the WB stage of the lw instruction. If we didn’t insert this no-op, the ID stage of the xor would coincide with the Mem stage of the lw.

Please give thumbsup, if you like it. Thanks.

Add a comment
Know the answer?
Add Answer to:
(Computer Architecture MIPS Assembly) Using minimum amount of nops - rewrite the code segment below so...
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
  • I just need part (d) answered 7) [24 marks] Consider the following MIPS code segment that is executed on a 5-stage pipeline architecture that does not implement forwarding or stalling in hardware....

    I just need part (d) answered 7) [24 marks] Consider the following MIPS code segment that is executed on a 5-stage pipeline architecture that does not implement forwarding or stalling in hardware. (1) add $4, $1, $1 (2) add $7, $4, $9 (3) lw $2, 400S8) (4) sub $8, $1, $2 (5) SKSs, so($2) (6) sub $2, $8, $4 (7) lw $3, 2($1) (8) add $8, $4, $2 Identify the data dependences that cause hazards. You are to use the...

  • 7 [24 marks] Consider the following MIPS code segment that is executed on a 5-stage pipeline architecture that does not implement forwarding or stalling in hardware. (1) add $4, $1, $1 (2) add $7,...

    7 [24 marks] Consider the following MIPS code segment that is executed on a 5-stage pipeline architecture that does not implement forwarding or stalling in hardware. (1) add $4, $1, $1 (2) add $7, $4, $9 (3) lw $2, 40($8) (4) sub $8, $1, $2 (5) sw $8, 80(S2) (6) sub $2, $8, $4 (7) lw S8, 2($1) (8) add $8, $4, S2 Identify the data dependences that cause hazards. You are to use the following format to inform each...

  • a).For the following MIPS assembly code to be executed using the pipelined datapath, identify all of...

    a).For the following MIPS assembly code to be executed using the pipelined datapath, identify all of the data dependencies (which register in which instruction needs the result register value from which another instruction?) and enumerate them (give them numbers as 1,2, ...). b).Which dependencies are data hazards that will be resolved via forwarding and without a stall (you can specify the number(s) from the part a)? c).Which dependencies are data hazards that will cause a stall (you can specify the...

  • Write MIPS code for each of the following instructions, Your assembly should implement the C code...

    Write MIPS code for each of the following instructions, Your assembly should implement the C code directly – i.e.,do not ’optimize’ the C code to change the order of operations or reduce computations. Use commands only like add, sub, lw, sw, immediate Part 1. x = 3-13*x; Do not use multiply. One way of doing the multiply without a multiply instruction is by using many add instructions (x+x+...+x). For this problem, you should do it with fewer additions. Hint: We...

  • MIPS Assembly Computer Organization and Design MIPS Algorithm Design (25 pts. Throughout the course, we have...

    MIPS Assembly Computer Organization and Design MIPS Algorithm Design (25 pts. Throughout the course, we have learned different types of instruction sets in MIPS programming: arithmetic instructions, branch instructions, jump instructions, and memory access instructions. Let's assume, we have a 10 line of MIPS code in which we perform 5 arithmetic operations, 2 branch operations. 1 jump operation, and 2 memory operations (1 store, 1 load). In the datapath, we are given that: fetching the instruction set takes 2 states....

  • Assembly code time

    Consider the following assembly language code:I0: add $R4,$R1,$R0                             //ADD R4 = R1 + R0;I1: lw $R1,100($R3)                             //LDW R1 = MEM[R3 + 100];I2: lw $R9,4,($R1)                                // LDW R9 = MEM[R1 + 4];I3: add $R3,$R4,$R9                             //ADD R3 = R4 + R9;I4: lw $R1,0($R3)                                 //LDW R1 = MEM[R3 + 0];I5: sub $R3,$R1,$R4                             //SUB R3 = R1 - R4;I6: and $R9,$R9,$R7                             //AND R9 = R9 & R7;I7: sw $R2,100($R4)                             //STW MEM[R4 + 100] = R2;I8: and $R4,$R2,$R1                             //AND R4 = R2 & R1;I9: add...

  • Computer science organization and architecture! Help! Instructions The answers to questions below must be written in...

    Computer science organization and architecture! Help! Instructions The answers to questions below must be written in the file named you MUST replace which has been provided with this test. Important: login the FSUl of the filename with you actual FSU login ID. That file has lines that begin with Question N. where N corresponds to the question number. Below or beside each Question N. there are placeholder as described must be replaced with the correct answer in the specific formats,...

  • Given the following sequence of instructions: lw $s2, 0($s1) //1 lw $s1, 40($s3) //2 sub $s3,...

    Given the following sequence of instructions: lw $s2, 0($s1) //1 lw $s1, 40($s3) //2 sub $s3, $s1, $s2 //3 add $s3, $s2, $s2 //4 or $s4, $s3, $zero //5 sw $s3, 50($s1) //6 a. List the read after write (current instruction is reading certain registers which haven’t been written back yet) data dependencies. As an example , 3 on 1 ($s2) shows instruction 3 has data dependency on instruction 1 since it is reading register $s2. b. Assume the 5...

  • (Computer structure)For the MIPS datapath shown below, several lines are marked with "X". (a) If the line is cut...

    (Computer structure)For the MIPS datapath shown below, several lines are marked with "X". (a) If the line is cut at place 1. Which of the following two instructions will not work? Briefly explain why. Add $1, $2,$3 SW $1,100($2) (b)If the line is cut at place 2, which code snippet will not work? Briefly explain. Code snippet 1: Add $1, $2, $3 Add $4, $1, $1 Code snippet 2: Add $1, $2,$3 Add $4, $5,$6 (C) If the line is...

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