Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For the following MIPS programming exercise, you may use only these instructions

ID: 3884664 • Letter: F

Question

For the following MIPS programming exercise, you may use only these instructions or macros:

add addi addiu addu and andi div divu li lui lw mfhi mflo mult multu nor or ori sll sra srl sub subu sw xor xori

Evaluate the polynomial:

2x3 - 3x2 + 5x + 12

Use symbolic addresses for variables x and answer (holds the result). Assume that the value in x is small enough so that all results fit into 32 bits. Since load delays are turned on in SPIM be careful what instructions are placed in the load delay slot.

Verify that the program works by using several initial values for x. Use x = 0 and x = 1 to start since this will make debugging easy. Then try some other values, such as x = 10 and x = -1.

Write the program following the hardware rule that two or more instructions must follow a mflo instruction before another mult instruction (the delay slot). Try to put useful instructions in the delay slots that follow the mflo.

Explanation / Answer

Answer

2x3 - 3x2 + 5x + 12

Load R1, X3
$L1= R1*2
Store L1

Load R2, X2
$L2= R2*2
Store L2

Load R3, x1
$L3= R3*5
Store L3

ori $1, $0, 32 #store 12 in $1

Add ($L1,$L2,$L3,$1)

If we put x3=5,x2=4,x1=6

2x3 - 3x2 + 5x + 12
=2*5-3*4+5*6+12

=10-12+30+12=40