Question: Your assembly code should implement the C code directly ( i.e. , do not 'optimize' the C code to change the order of operations or

Your assembly code should implement the C code directly (i.e., do not 'optimize' the C code to change the order of operations or reduce computations).

1. x = 9-11*i; One way of doing the multiply without a multiply instruction is by using many add instructions (i+i+...+i). For this problem, you should do it with fewer additions.

2. a[j+2] = 4*j - a[2*j-3]); Try to do it as efficiently as possible (under a 1CPI assumption).

For all problems, make sure that you state the register allocation at the top of the code, using the style of our example below (for x=a+b-c): # Register allocation: # x-->$s2 a-->$s0 b-->$s1 c-->$s3 # add $t0,$s0,$s1 # $t0 <-- a+b sub $s2,$t0,$s3 # x <-- a+b-c

Hints:

Prob 1: Note that we do not have a multiply instruction (yet). However, we already know how to multiply by powers of 2, and we also know how to express any number as a sum of powers of 2 (e.g., 7=4+2+1).

Prob 2: If you are having trouble with this, you should probably practice on something simpler such as a[j]=x or x=a[2*j-3]. Its always a good idea (in any class) to come up with simpler subproblems to practice on if you are having problems.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!