Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

Rewrite the loop from Exercise 2.29 to reduce the number of MIPS instructions executed

Short Answer

Expert verified

The reduce number of Mips instructions are:

addi $t1, $s0, 400

LOOP: lw $s1, 0($t1)

add $s2, $s2, $s1

addi $t1, $t1, -4

bne $t1, $s0 LOOP

Step by step solution

01

MIPS instructions used in Exercise 2.29

addi: It is short for add immediate

lw: It is short for load word

add: It is an arithmetic operation used to add

slti: It is short for set on less than or equal

bne: it is short for the branch on not equal it test if registers are not equal

02

Given MIPS instruction

addi $t1, $0, $0

LOOP: lw $s1, 0($s0)

add $t2, $s0

addi $s0. $s0, 4

addi $t1, $t1, 1

slti $t2, $t1, 100

bne $t2, $s0, LOOP

03

Rewrite the loop to Minimize the number of MIPS instruction

Here, we used variable only for loop control

Now, reduce the number of MIPS instruction

addi $t1, $s0, 400 # add a constant number

LOOP: lw $s1, 0($t1) # load word

add $s2, $s2, $s1 # add first element

addi $s2, $s2, $s1 # add immediate and immediate means a constant no.

bne $t1, $s0, LOOP #Loop until the pointer reaches limit

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Most popular questions from this chapter

Question: Assume the following register contents:

  1. For the register values shown above, what is the value of \(t2 for the following sequence of instructions?

sll \)t2,\(t0,44

or \)t2,\(t2,\)t1

  1. For the register values shown above, what is the values of \(t2 for the following sequence of instructions?

sll \)t2,\(t0,4

andi \)t2,\(t2,-1

  1. For the register values shown above, what is the value of \)t2 for the following sequence of instructions?

srl \(t2,\)t0,3

andi \(t2,\)t2, 0xFFEF

[5] Consider the following MIPS loop:

LOOP: slt \(t2, \)0, \(t1

beq \)t2, \(0, DONE

subi \)t1, \(t1, 1

addi \)s2, \(s2, 2

j LOOP

DONE:

2.26.1 [5] <§2.7> Assume that the register \)t1 is initialized to the value 10. What is the value in register \(s2 assuming \)s2 is initially zero?

2.26.2 [5] <§2.7> For each of the loops above, write the equivalent C code routine. Assume that the registers \(s1, \)s2, \(t1, and \)t2 are integers A, B, i, and temp, respectively.

2.26.3 [5] <§2.7> For the loops written in MIPS assembly above, assume that the register $t1 is initialized to the value N. How many MIPS instructions are executed?

Question: [5] Assume for a given processor the CPI of arithmetic instructions is 1, the CPI of load/store instructions is 10, and the CPI of branch instructions is 3.

Assume a program has the following instruction breakdowns: 500 million arithmetic instructions, 300 million load/store instructions, 100 million branch instructions.

2.46.1 [5] <§2.19> Suppose that new, more powerful arithmetic instructions are added to the instruction set. On average, through the use of these more powerful arithmetic instructions, we can reduce the number of arithmetic instructions needed to execute a program by 25%, and the cost of increasing the clock cycle time by only 10%. Is this a good design choice? Why?

2.46.2 [5] <§2.19> Suppose that we find a way to double the performance of arithmetic instructions. What is the overall speedup of our machine? What if we find a way to improve the performance of arithmetic instructions by 10 times?

Question: Assume that for a given program 70% of the executed instructions are arithmetic, 10% are load/store, and 20% are branch.

2.47.1 [5] <§2.19> Given this instruction mix and the assumption that an

arithmetic instruction requires 2 cycles, a load/store instruction takes 6 cycles, and a branch instruction takes 3 cycles, find the average CPI.

2.47.2 [5] <§2.19> For a 25% improvement in performance, how many cycles, on average, may an arithmetic instruction take if load/store and branch instructions are not improved at all?

2.47.3 [5] <§2.19> For a 50% improvement in performance, how many cycles, on average, may an arithmetic instruction take if load/store and branch instructions are not improved at all?

If the current value of the PC is 0x00000000, can you use a single jump instruction to get to the PC address as shown in Exercise 2.39?

See all solutions

Recommended explanations on Computer Science Textbooks

View all explanations

What do you think about this solution?

We value your feedback to improve our textbook solutions.

Study anywhere. Anytime. Across all devices.

Sign-up for free