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

For the MIPS assembly instructions in Exercise 2.4, rewrite the assembly code to minimize the number if MIPS instructions (if possible) needed to carry out the same function.

Short Answer

Expert verified

It is possible to lower the number of MIPS instructions by one. After reduction, the total number of MIPS instructions is 8.

Step by step solution

01

Determine the MIPS instructions

The instruction addi $t2, $t0, 4 can be removed from the sequence of instructions to be examined. This is due to the fact that it adds 4 to the address of $t0 and puts the result in $t2. The value of $t2 is obtained and stored in the register $t0.

The value of $t0 at memory position 4 is immediately retrieved and loaded into the register $t0 during the minimizing of operations.

Consider the following MIPS instructions:

sll$t0,$s0,2#$t0=f*4add$t0,$s6,$t0#$t0=&Afsll$t1,$s1,2#$t1=g*4add$t1,$s7,$t1#$t1=&Bglw$s0,0$t0#f=Afaddi$t2,$t0,4#$t2=&Af+1lw$t0,0$t2#$t0=Af+1add$t0,$t0,$s0#$t0=Af+1+Afsw$t0,0$t1#Bg=$t0

02

Minimizing the number of instructions:

It is possible to lower the number of MIPS instructions by one. After reduction, the total number of MIPS instructions is 8.

sll$t0,$s0,2#$t0=f*4add$t0,$s6,$t0#$t0=&Afsll$t1,$s1,2#$t1=g*4add$t1,$s7,$t1#$t1=&Bglw$s0,0$t0#f=Aflw$t0,4$t0#$t0=Af+1add$t0,$t0,$s0#$t0=Af+1+Afsw$t0,0$t1#Bg=$t0

Unlock Step-by-Step Solutions & Ace Your Exams!

  • Full Textbook Solutions

    Get detailed explanations and key concepts

  • Unlimited Al creation

    Al flashcards, explanations, exams and more...

  • Ads-free access

    To over 500 millions flashcards

  • Money-back guarantee

    We refund you if you fail your exam.

Over 30 million students worldwide already upgrade their learning with Vaia!

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 2.4 [5] For the MIPS assembly instructions below, what is the corresponding C statement? 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.

sll \)t0, \(s0, 2 # \)t0 = f * 4

add \(t0, \)s6, \(t0 # \)t0 = &A[f]

sll \(t1, \)s1, 2 # \(t1 = g * 4

add \)t1, \(s7, \)t1 # \(t1 = &B[g]

lw \)s0, 0(\(t0) # f = A[f]

addi \)t2, \(t0, 4

lw \)t0, 0(\(t2)

add \)t0, \(t0, \)s0

sw \(t0, 0(\)t1)

Question: Translate into decimal.

Assume that \(s0 holds the value 128ten.

  1. For the instruction add \)t0, \(s0, \)s1, what is the range(s) of values for \(s1 that would result in overflow?
  2. For the instruction sub \)t0, \(s0, \)s1, what is the range(s) of values for \(s1 that would result in overflow?
  3. For the instruction sub \)t0, \(s1, \)s0, what is the range(s) of values for $s1 that would result in overflow?

Question: Functions can often be implemented by compilers โ€œin-lineโ€. An in-line function is when the body of the function is copied into the program space, allowing the overhead of the function call to be eliminated, Implement an โ€œin-lineโ€ version of the C code above in MIPS assembly. What is the reduction in the total number of MIPS assembly instructions needed to complete the function? Assume that the C variable n is initialized to 5.

If the current value of the PC is 0x00000600, 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