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: 3885054 • 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

The machine supports a very limited form of the

syscall

instruc-

tion as was specified in Lab 1: if register

$r2

has a value of

0xA

when a

syscall

instruction is

invoked, it signals the end of the program (and also dumps out the register values). To mini-

mize the confusion, we have the

syscall

instruction already implemented in the supplementary

source code that we provide.

Exceptions.

The machine does

not

support exceptions. The machine assumes that all instruc-

tions execute correctly and does not even bother to check for exceptions. (For example, operands

to an

ADDI

instruction are

guaranteed

not to overflow their output. So the machine does not

check whether the carry-outs of the most-significant two bits are different from each other.)

CMU 18-447 – Introduction to Computer Architecture – Spring 2013

2/6

Branch Delay Slot.

The machine does

not

support a branch delay slot after a jump or

branch instruction. (We are being consistent with Lab 1.) This means two things. First, the

instruction at the target-address of the jump/branch instruction is executed

immediately

after

the jump/branch instruction (for a branch instruction, this is assuming that the branch condition

is true). Second, some of the jump/branch instructions operate differently from their definitions

in the

MIPS R4000 User’s Manual