Thursday, 29 October 2015 Please respond to the survey (see email)! - - PowerPoint PPT Presentation
Thursday, 29 October 2015 Please respond to the survey (see email)! - - PowerPoint PPT Presentation
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
Last time: Floating Point
Floating point calculations in MIPS (BRIEF!) Uses a separate processor (called coprocessor 1) with its own set
- f 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
- perand
n-bit
- perand
n-bit result
Symbols
- 111
321 + 210 (result)
Algorithm from Last Tuesday
NOTE: requires a 64-bit ALU
Refined Algorithm--32-bit ALU
Refined Algorithm--32-bit ALU
Example: 7 x 9
0000 ... 0111 0000 ... 0000 0000 ... 1001 multiplicand multiplier product
INITIAL SETUP
multiplier = 1, so add multiplicand to product...
0000 ... 0111 0000 ... 0011 1000 ... 0100 multiplier product
...and shift right 1
Refined Algorithm--32-bit ALU
Example: 7 x 9
multiplier = 0, so don’t add multiplicand; shift right
0000 ... 0111 0000 ... 0011 1000 ... 0100 multiplier product 0000 ... 0111 0000 ... 0001 1100 ... 0010 multiplier product
Refined Algorithm--32-bit ALU
Example: 7 x 9
multiplier = 0, so don’t add multiplicand; shift right
0000 ... 0111 0000 ... 0001 1100 ... 0010 multiplier product 0000 ... 0111 0000 ... 0000 1110 ... 0001 multiplier product
Refined Algorithm--32-bit ALU
Example: 7 x 9
multiplier = 1, so add multiplicand...
0000 ... 0111 0000 ... 0000 1110 ... 0001 multiplier product 0000 ... 0111 0000 ... 0011 1111 ... 0000 multiplier product
1 ...and shift right
Refined Algorithm--32-bit ALU
Example: 7 x 9
all remaining multiplier bits are 0, so just shift right 28 more times...
0000 ... 0111 0000 ... 0011 1111 ... 0000 multiplier product 0000 ... 0111 0000 ... 0000 0...0011 1111 product
PRODUCT = 111111 (63ten)
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
- 110
001 (nonneg. so 1 in quotient; shift divisor)
- 11
negative! (so 0 in quotient, add back 11) + 11 001 (remainder) Quotient: 10two = 2 Remainder: 1
(Pad divisor with 0s on the right)
Integer Division
One more example: 58/5: 111010
- 101000
010010 (nonneg. so 1 in quotient)
- 10100
negative! (add back, 0 in quotient) 010010
- 1010
001000 (nonneg. so 1 in quotient)
- 101