























































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This lecture was delivered by Mr. Gurpreet Verma at Cochin University of Science and Technology for Assembly Language Programming course. It includes: Multiplying, Hardware, Software, Dividing, Floating, Arithmetic, Dangers, Algorithm, Notation, Binary, Normalize, Exponent
Typology: Slides
1 / 63
This page cannot be seen from the preview
Don't miss anything!
























































Chapter 4.2 - Mult, Div, Float
1
Chapter 4.2 - Mult, Div, Float
2
U 1001 Multiplier^
M (^100000000000) 100001001000 Product^
P
-^ Binary multiplication is easy:^ –^ P == 0^ ^ place all 0's i^
(0^ ^ multiplicand)
-^ P == 1^ ^ place a copy of i^
U^ (1^ ^ multiplicand)
add,^ sll?
Chapter 4.2 - Mult, Div, Float
4
sll^ and^ add instructions:^ i'^ =^ i^
*****^10 ;^ /*^ assume
i:^ $s0^ */ sll^ $t0,^ $s0,^3
(^3) # i * 2 add^ $t1,^ $zero,^
$t sll^ $t0,^ $s0,^1
(^1) # i * 2 add^ $s0,^ $t1,^ $t0 • MIPS multiply instructions:^ mult
,^ multu
-^ mult^ $t0,^ $t1^ – puts 64-bit product in pair of new registers
hi,^ lo; copy to $n by mfhi,^ mflo – 32-bit integer result in register
lo
Chapter 4.2 - Mult, Div, Float
5
-^ Shifting right by^ n
bits would seem to be the same as dividing by 2
n
-^ Problem is signed integers^ – Zero fill (srl) is wrong for negative numbers•^ Shift Right Arithmetic (
; result should be -11111 1111 1111 1111 1111 1111 1111 10111111 1111 1111 1111 1111 1111 1111 1110
-^ = -2, not -1; Off by 1, so
Chapter 4.2 - Mult, Div, Float
7
1. TestMultiplier^0 2. Shift the Product register right 1 bit. 3. Shift the Multiplier register right 1 bit.No: < 32 repetitionsYes: 32 repetitionsDone Multiplier^ = 0^0 Multiplier0 = 1 1a. Add multiplicand to the left half of product &place the result in the left half of Product register
Start 32ndrepetition? Product^ Multiplier Multiplicand^ 0000 0000^0011 0010 1:^ 0010 0000^0011 0010 2:^ 0001 0000^0011 0010 3:^ 0001 0000^0001 0010 1:^ 0011 0000^0001 0010 2:^ 0001 1000^0001 0010 3:^ 0001 1000^0000 0010 1:^ 0001 1000^0000 0010 2:^ 0000 1100^0000 0010 3:^ 0000 1100^0000 0010 1:^ 0000 1100^0000 0010 2:^ 0000 0110^0000 0010 3:^ 0000 0110^0000 0010 0000 0110^0000
Chapter 4.2 - Mult, Div, Float
8
(or^ Modulo^ result) See^ how^ big^ a^ number
can^ be^ subtracted,
creating quotient^ bit^ on^
each^ step Binary => 1 * divisor or 0 * divisor Dividend^ =^ Quotient
^ Divisor^ +^ Remainder
|^ Dividend^ |^ =^ |
Quotient^ |^ +^ |^
Divisor^ |
Chapter 4.2 - Mult, Div, Float
10
divisor^ starts in left½ of Divisor reg. and it is shiftedright 1 on each step; Remainder = dividend ; If Remainder < 0, we need to add Divisorback to dividend ; else 1 is generatedfor Quotient;Shift Divisor right 1 bit;Repeat 33 times Start: Place Dividend in Remainder1. Subtract the Divisor register from theRemainder register, and place the resultin the Remainder register.Remainder < 0Remainder 0 TestRemainder 2b. Restore the original value by adding the2a. Shift theDivisor register to the Remainder register, &Quotient registerplace the sum in the Remainder register. Alsoto the left settingshift the Quotient register to the left, settingthe new rightmostthe new least significant bit to 0.bit to 1.3. Shift the Divisor register right 1 bit. n +1No: <^ n +1 repetitionsrepetition?Yes: n+1 repetitions ( n^ = 4 here)Done Let $s0 = Dividend,$s1 = Divisor,$s2 = Remainder,$s3 = Quotient,$s4 = RepetitionsStart:move^ $s2, $s0Loop:sub^ $s2, $s2, $s
Label2b:add^ $s2, $s2, $s
Label3:slr^ $s1, $s1, 1
Chapter 4.2 - Mult, Div, Float
11
0000 1:^1110
00000 0010 0000 2:^0000
00000 0010 0000 3:^0000
00000 0001 0000 1:^1111
00000 0001 0000 2:^0000
00000 0001 0000 3:^0000
00000 0000 1000 1:^1111
00000 0000 1000 2:^0000
00000 0000 1000 3:^0000
00000 0000 0100 1:^0000
00000 0000 0100 2:^0000
00001 0000 0100 3:^0000
00001 0000 0010 1:^0000
00001 0000 0010 2:^0000
00011 0000 0010 3:^0000
00011 0000 0010
Chapter 4.2 - Mult, Div, Float
13
Chapter 4.2 - Mult, Div, Float
14
-^ Normal form:no leading 0s (digit 1 to left of decimal point) •^ Alternatives to representing 1/1,000,000,000^ Normalized:^
-91.0 × 10-8-10Not normalized: 0.1 × 10, 10.0 × 10
Chapter 4.2 - Mult, Div, Float
16
0 3130 23 22S^ Exponent
Significand 1 bit^ 8 bits^
23 bits
E
(^38) °^ Relationship between Mantissa and Significand bits?Between E and Exponent? °^ In C type^ float
Chapter 4.2 - Mult, Div, Float
17
Chapter 4.2 - Mult, Div, Float
19
Exponent × 2 , where 0 < Significand < 1 • If label significand bits left-to-right as s
, s, s, ... then value is: 123 S^ -1(-1) ×^ (1+(s ×^2 ) + (s^1
-2-3 × 2 ) + (s ×^2 ) +^ ) 22
Exponent × 2
Chapter 4.2 - Mult, Div, Float
20
^ bigger number (^20 10) 1.1 × 10 > 1.9^ ×^10 • What About Negative Exponents?-1^ Use 2’s comp? 1.0 ×^2 vs. 1.0^ × +1^2 (1/2 v. 2)