Thursday, 29 October 2015 Please respond to the survey (see email)! Exam date (currently Thu. 5 Nov; change?) Questions about lab? Today: Finish up chapter 3 Start reading chapter 4 (and Appendix B)
Last time: Floating Point Floating point calculations in MIPS (BRIEF!) Uses a separate processor (called coprocessor 1) with its own set of registers $f0, $f1, ...
Floating Point in MIPS (examples) Put a float value in memory: x: .float 3.14159 Put a double in memory: .align 3 # double-word alignment d: .double 3.1415926535 Load a float into register $f0 : lwc1 $f0,x Add two floating-point registers: add.s $f2,$f0,$f1
Floating Point in MIPS (examples) Store a floating point register in memory: swc1 $f0,z Print a float: lwc1 $f12,z # place it in $f12 li $v0,2 # 3 = code for print_float syscall See program “float.asm” for a short, simple example. Exploring float and double in MIPS would be a good final project!
Back to Integer Multiplication On Oct. 20 we looked at a multiplication algorithm. Let’s look at a few symbols used in the book. A sort-of V-shaped symbol stands for the Arithmetic- Logic Unit:
Symbols n-bit operand n-bit result n-bit operand
Symbols + -111 210 (result) 321
Algorithm from Last Tuesday NOTE: requires a 64-bit ALU
Refined Algorithm--32-bit ALU
Refined Algorithm--32-bit ALU Example: 7 x 9 multiplicand 0000 ... 0111 INITIAL SETUP 0000 ... 0000 0000 ... 100 1 product multiplier multiplier = 1, so add multiplicand to product... 0000 ... 0111 ...and shift right 0000 ... 0011 1000 ... 0100 1 product multiplier
Refined Algorithm--32-bit ALU Example: 7 x 9 0000 ... 0111 0000 ... 0011 1000 ... 010 0 product multiplier multiplier = 0, so don’t add multiplicand; shift 0000 ... 0111 right 0000 ... 0001 1100 ... 0010 0 product multiplier
Refined Algorithm--32-bit ALU Example: 7 x 9 0000 ... 0111 0000 ... 0001 1100 ... 001 0 product multiplier multiplier = 0, so don’t add multiplicand; shift 0000 ... 0111 right 0000 ... 0000 1110 ... 0001 0 product multiplier
Refined Algorithm--32-bit ALU Example: 7 x 9 0000 ... 0111 0000 ... 0000 1110 ... 000 1 product multiplier multiplier = 1, so add multiplicand... 0000 ... 0111 ...and shift right 0000 ... 0011 1111 ... 0000 1 product multiplier
Refined Algorithm--32-bit ALU Example: 7 x 9 0000 ... 0111 0000 ... 0011 1111 ... 000 0 product multiplier all remaining multiplier bits are 0, so just shift 0000 ... 0111 right 28 more times... PRODUCT = 111111 0000 ... 0000 0...0011 1111 (63 ten ) product
What About Integer Division? Basic idea (let’s only look at positive #s) dividend / divisor = quotient, remainder Ex: 100/9 = quotient 11, remainder 1 7/9 = quotient 0, remainder 7 This satisfies: quotient x divisor + remainder = dividend
Integer Division? Basic idea : Repeatedly subtract dividend from divisor, shifting right each time and “unsubtracting” if result becomes negative. Example: 7/3: 111 (Pad divisor with 0s on the right) - 110 001 (nonneg. so 1 in quotient; shift divisor) - 11 negative! (so 0 in quotient, add back 11) + 11 Quotient: 10 two = 2 001 (remainder) Remainder: 1
Integer Division Quotient: 1011 two =11 ten One more example: 58/5: Remainder: 11 two = 3 ten 111010 - 101000 Note how 010010 (nonneg. so 1 in quotient) we shift the - 10100 divisor one negative! (add back, 0 in quotient) place to the 010010 right each - 1010 time we 001000 (nonneg. so 1 in quotient) subtract - 101 000011 (nonneg., so 1 in quotient)
Division in MIPS Similar to multiplication, it use two special registers named “lo” and “hi”. When we divide, the quotient goes into the “lo” register and the remainder goes into the “hi” register. lw $s0,a # dividend lw $s1,b # divisor div $s0,$s1 # hi = s0/s1, lo = s0%s1 See program mflo $t0 # t0 = quotient “divide.asm” for mfhi $t1 # t1 = remainder an example.
Recommend
More recommend