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: 3884878 • Letter: F

Question

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

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

Write an MIPS program that determines the value of this expression:   (x*y)/z

Use x = 160000010 (=0x00186A00), y = 8000010 (=0x00013880), and z = 40000010 (=0x00061A80). Initialize three registers to these values. Since the immediate operand of the ori instruction is only 16 bits wide, use shift instructions to move bits into the correct locations of the registers. Don't use any macros for this program. This problem is somewhat tricky, because the expression (x*y) will have a result that is bigger than 32 bits long. Therefore, choose the order of multiply and divide operations so that the significant bits always remain in the lo result register.

Explanation / Answer

PROGRAM

ori $8, $0, 1562 #x- 1600000- all shifted right, needs to be shifted left to be 32 bit, its shift is 10
ori $9, $0, 78 #y- 80000- shifted right 10, needs to be shifted left to be 32 bit wide
ori $10, $0, 390 #z- 400000- shifted right 10, needs to be shifted left to be 32 bit wide

ori $11, $0, 0 #temp register

multu $8, $9 #x * y
mflo $11 #temporarily store the result of x and y

nop
nop

divu $11, $10 #divides z by the result of x * y
mflo $11 #stores the result in register 11

sll $11, $11, 10 #shifts the binary left

END OF THE PROGRAM

THANK YOU