Thursday, 29 October 2015 Please respond to the survey (see email)! - - PowerPoint PPT Presentation

thursday 29 october 2015
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

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)

slide-2
SLIDE 2

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, ...

slide-3
SLIDE 3

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

slide-4
SLIDE 4

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!

slide-5
SLIDE 5

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:

slide-6
SLIDE 6

Symbols

n-bit

  • perand

n-bit

  • perand

n-bit result

slide-7
SLIDE 7

Symbols

  • 111

321 + 210 (result)

slide-8
SLIDE 8

Algorithm from Last Tuesday

NOTE: requires a 64-bit ALU

slide-9
SLIDE 9

Refined Algorithm--32-bit ALU

slide-10
SLIDE 10

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

slide-11
SLIDE 11

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

slide-12
SLIDE 12

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

slide-13
SLIDE 13

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

slide-14
SLIDE 14

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)

slide-15
SLIDE 15

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

slide-16
SLIDE 16

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)

slide-17
SLIDE 17

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

000011 (nonneg., so 1 in quotient) Quotient: 1011two =11ten Remainder: 11two= 3ten Note how we shift the divisor one place to the right each time we subtract

slide-18
SLIDE 18

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 mflo $t0 # t0 = quotient mfhi $t1 # t1 = remainder See program “divide.asm” for an example.