Last name __Solutions _____ First name _________________
Section _________

CSE378 Autumn 2003
Miniquiz #2
1 pt. per part except as noted
No calculators!

1-4. Filll in the blanks:  On the MIPS architecture, there are _32_ general-purpose registers, each _32_ bits in length.  There are a handful of special-purpose registers, for example pick two from {$gp, $sp, $fp, $ra, $at, hi, lo, $zero, pc}

5. Answer T/F and explain briefly: The general purpose registers do double-duty as floating point registers.

False: MIPS has a separate set of floating point registers.


6-7-8. Suppose register $t1 contains a value (a signed integer, call it x), and we want to compute the value of 3*x + 5 and leave it in $v0.  Write MIPS instructions to do so.

Many different ways.  One way:

add $v0, $t1, $t1   # v0 = 2x
add $v0, $v0, $t1  # v0 = 3x
addi $v0, $v0, 5    # v0 = 3x + 5

If you used multiplication to get 3x, keep in mind there's no "multi" instruction that takes an integer constant, like multi $v0, $t1, 3.  If you wanted to use a multiply instruction, you'd have to first load the constant 3 into a register, then do the mult. 

9. Instead of $t1 having the value of x, suppose $a0 contains the memory address of x.  We still want to compute 3*x + 5.   How would the program differ?

It would have  lw $t1, 0($a0) on top, everything else stays the same.



10. On some machines, the terms "branch" and "jump" are loosely interchanged.  In MIPS, there is a clear difference between the "branch" and "jump" instructions.  Explain briefly.

Jumps are always unconditional, while branches usually have a condition controlling whether the branch is taken.


Another possible answer:

Branches are PC-relative: they have a 16-bit signed offset which tells us where to jump relative to the current instruction.  Thus, they can transfer control up to 2^15 instructions backward or 2^15-1 instructions forward.

Jumps use an absolute address either encoded in a 26-bit field in the instruction or passed in a register (e.g. jr $31).   Thus, jumps can go to addresses farther away and they don't depend (well, almost) on the current instruction address.