Arithmetic circuit

Download Report

Transcript Arithmetic circuit

Number Systems (1)

Positional Notation
N = (an-1an-2 ... a1a0 . a-1a-2 ... a-m)r
(1.1)
where
. = radix point
r = radix or base
n = number of integer digits to the left of the radix point
m = number of fractional digits to the right of the radix point
an-1 = most significant digit (MSD)
a-m = least significant digit (LSD)

Polynomial Notation (Series Representation)
N n=1 an-1
x rn-1 + an-2 x rn-2 + ... + a0 x r0 + a-1 x r-1 ... + a-m x r-m
i
 ai r
=
i  m

(1.2)
N = (251.41)10 = 2 x 102 + 5 x 101 + 1 x 100 + 4 x 10-1 + 1 x 10-2
Number Systems (2)

Binary numbers



Digits = {0, 1}
(11010.11)2 = 1 x 24 + 1 x 23 + 0 x 22 + 1 x 21 + 0 x 20 + 1 x 2-1
+ 1 x 2-2
= (26.75)10
1 K (kilo) = 210 = 1,024, 1M (mega) = 220 = 1,048,576,
1G (giga) = 230 = 1,073,741,824

Octal numbers



Digits = {0, 1, 2, 3, 4, 5, 6, 7}
(127.4)8 = 1 x 82 + 2 x 81 + 7 x 80 + 4 x 8-1 = (87.5)10
Hexadecimal numbers


Digits = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F}
(B65F)16 = 11 x 163 + 6 x 162 + 5 x 161 + 15 x 160 = (46,687)10
Number Systems (3)

Important Number Systems (Table 1.1)
Decimal
0
1
2
3
5
6
7
8
9
10
11
12
13
14
15
16
Binary
0
1
10
11
100
101
110
111
1000
1001
1010
1011
1100
1101
1110
1111
10000
Octal
0
1
2
3
4
5
6
7
10
11
12
13
14
15
16
1
20
Hexadecimal
0
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F
10
Powers of 2
Powers of 2
20
21
22
23
24
25
26
27
28
29
210
211
212
213
214
215
216
Decimal Equivalent
1
2
4
8
16
32
64
128
256
512
1,024
2,048
4,096
8,192
16,384
32,768
65,536
Abbreviation
1K
2K
4K
8K
16K
32K
64K
Decimal-Binary Equivalences
Decimal
1
3
7
15
31
63
127
255
511
1,023
2,047
4,095
8,191
16,383
32,767
65,535
Binary
1
11
111
1111
1 1111
11 1111
111 1111
1111 1111
1 1111 1111
11 1111 1111
111 1111 1111
1111 1111 1111
1 1111 1111 1111
11 1111 1111 1111
111 1111 1111 1111
1111 1111 1111 1111
Hexadecimal
1
3
7
F
1F
3F
7F
FF
1FF
3FF
7FF
FFF
1FFF
3FFF
7FFF
FFFF
Base Conversion (1)

Series Substitution Method


Expanded form of polynomial representation:
N = an-1rn-1 + … + a0r0 + a-1r-1 + … + a-mr-m
Conversation Procedure (base A to base B)



Represent the number in base A in the format of Eq. 1.3.
Evaluate the series using base B arithmetic.
Examples:


(11010)2 ®( ? )10
N = 1´24 + 1´23 + 0´22 + 1´21 + 0´20
= (16)10 + (8)10 + 0 + (2)10 + 0
= (26)10
(627)8 ® ( ? )10
N = 6´82 + 2´81 + 7´80
= (384)10 + (16)10 + (7)10
= (407)10
(1.3)
Base Conversion (2)

Radix Divide Method


Used to convert the integer in base A to the equivalent base
B integer.
Underlying theory:

(NI)A = bn-1Bn-1 + … + b0B0
(1.4)
Here, bi’s represents the digits of (NI)B in base A.

NI / B  (bn-1Bn-1 + … + b1B1 + b0B0 ) / B
= (Quotient Q1: bn-1Bn-2 + … + b1B0 ) + (Remainder R0: b0)


In general, (bi)A is the remainder Ri when Qi is divided by (B)A.
Conversion Procedure
1. Divide (NI)B by (B)A, producing Q1 and R0. R0 is the least
significant digit, d0, of the result.
2. Compute di, for i = 1 … n - 1, by dividing Qi by (B)A, producing
Qi+1 and Ri, which represents di.
3. Stop when Qi+1 = 0.
Base Conversion (3)

Examples

(315)10 = (473)8
8 315
8 39
8 4
0

3
7
4
LSD
MSD
(315)10 = (13B)16
16 315
16 19
16 1
0
B
3
1
LSD
MSD
Base Conversion (4)

Radix Multiply Method


Used to convert fractions.
Underlying theory:




(NF)A = b-1B-1 + b-2B-2 + … + b-mB-m
(1.5)
Here, (NF)A is a fraction in base A and bi’s are the digits of (NF)B in
base A.
B ´ NF = B ´ (b-1B-1 + b-2B-2 + … + b-mB-m )
= (Integer I-1: b-1) + (Fraction F-2: b-2B-1 + … + b-mB-(m-1))
In general, (bi)A is the integer part I-i, of the product of F-(i+1) ´ (BA).
Conversion Procedure
1. Let F-1 = (NF)A.
2. Compute digits (b-i)A, for i = 1 … m, by multiplying Fi by (B)A,
producing integer I-i, which represents (b-i)A, and fraction F(i+1).
3. Convert each digits (b-i)A to base B.
Base Conversion (5)

Examples

(0.479)10 = (0.3651…)8
MSD
3.832 ¬ 0.479 ´ 8
6.656 ¬ 0.832 ´ 8
5.248 ¬ 0.656 ´ 8
LSD
1.984 ¬ 0.248 ´ 8
…

(0.479)10 = (0.0111…)2
MSD
0.9580 ¬ 0.479 ´ 2
1.9160 ¬ 0.9580 ´ 2
1.8320 ¬ 0.9160 ´ 2
LSD
1.6640 ¬ 0.8320 ´ 2
…
Base Conversion (6)



General Conversion Algorithm
Algorithm 1.1
To convert a number N from base A to base B, use
(a) the series substitution method with base B arithmetic, or
(b) the radix divide or multiply method with base A arithmetic.
Algorithm 1.2
To convert a number N from base A to base B, use
(a) the series substitution method with base 10 arithmetic to
convert N
from base A to base 10, and
(b) the radix divide or multiply method with decimal arithmetic
to convert
N from base 10 to base B.

Algorithm 1.2 is longer, but easier and less error prone.
Base Conversion (7)

Example
(18.6)9 = ( ? )11
(a) Convert to base 10 using series substitution method:
N10 = 1 ´ 91 + 8 ´ 90 + 6 ´ 9-1
= 9 + 8 + 0.666…
= (17.666…)10
(b) Convert from base 10 to base 11 using radix divide and multiply
method:
7.326 ¬ 0.666 ´ 11
11 17 6
3.586 ¬ 0.326 ´ 11
11 1 1
0
6.446 ¬ 0.586 ´ 11
.
N11 = (16.736 …)11
Base Conversion (8)

When B = Ak

Algorithm 1.3
(a) To convert a number N from base A to base B when B = Ak
and k is a positive integer, group the digits of N in groups of k
digits in both directions from the radix point and then replace
each group with the equivalent digit in base B
(b) To convert a number N from base B to base A when B = Ak
and k is a positive integer, replace each base B digit in N with
the equivalent k digits in base A.

Examples


(001 010 111. 100)2 = (127.4)8 (group bits by 3)
(1011 0110 0101 1111)2 = (B65F)16 (group bits by 4)
Binary addition
0+0=0
0+1=1
1+0=1
1 + 1 = 10 = 0 + carry of 1 into next position
1 + 1 + 1 = 11 = 1 + carry of 1 into next position
A
B
HALF
ADDER
SUM =
Carry-Out =
SUM
A
B
SUM
CO
CO
0
0
0
0
0
1
1
0
1
0
1
0
1
1
0
1
Binary addition
1-bit 8 Strings Full Adder with
Carry-In and Carry-Out
A
B
CI
FULL
ADDER
SUM =
Carry-Out =
SUM
CI
A
B
SUM
CO
0
0
0
0
0
0
0
1
1
0
0
1
0
1
0
0
1
1
0
1
1
0
0
1
0
1
0
1
0
1
1
1
0
0
1
1
1
1
1
1
CO
1-bit 8 Strings Full Adder with Carry-In and Carry-Out
A
B
CI
FULL
ADDER
SUM =
Carry-Out =
SUM
CO
Binary addition
Binary Subtraction
0
1
1
0
A
B
-
0
0
1
1
HALF
Subtractor
SUB =
Borrow-Out =
=
=
=
=
0
1
0
1 ต้องยืมจากหลักที่สูงกว่ามา 1
SUB
A
B
SUB
BO
BO
0
0
0
0
0
1
1
1
1
0
1
0
1
1
0
0
Binary Subtraction
1-bit 8 Strings Full Subtractor with
Borrow-In and Borrow -Out
A
B
BI
FULL
Subtractor
SUB =
SUB
BI
A
B
SUB
BO
0
0
0
0
0
0
0
1
1
1
0
1
0
1
0
0
1
1
0
0
1
0
0
1
1
1
0
1
0
1
1
1
0
0
0
1
1
1
1
1
BO
Borrow-Out =
REPRESENTING UNSIGNED NUMBERS
(Absolute value)
A7
A6
A5
A4
A3
A2
A1
A0
0
0
0
0
0
0
0
0
B7
1
B6
1
B5
B4
B3
B2
B1
B0
1
1
1
1
1
1
=00H
=FFH
REPRESENTING SIGNED NUMBERS
in sign-magnitude form.
A7
A6
A5
A4
A3
A2
A1
A0
0
0
1
1
0
1
0
0
Magnitude = 5210
SIGN BIT
B7
B6
1
SIGN BIT
=+5210
0
B5
B4
B3
B2
B1
B0
1
1
0
1
0
0
Magnitude = 5210
=-5210
REPRESENTING SIGNED NUMBERS
in the 2’ S-complement system.
A7
A6
A5
A4
A3
A2
A1
A0
0
0
1
0
1
1
0
1
True binary
SIGN BIT
B7
=+4510
B6
1
1
B5
B4
B3
B2
B1
B0
0
1
0
0
1
1
2’s complement
SIGN BIT
=-4510
Range of Sign-Magnitude Numbers
A7
A6
A5
A4
A3
A2
A1
A0
0
0
0
0
0
0
0
1
B5
B4
B3
B2
B1
B0
B7
SIGN BIT
B6
0
1
1
1
1
1
1
1
A7
A6
A5
A4
A3
A2
A1
A0
1
0
0
0
0
0
0
1
B5
B4
B3
B2
B1
B0
1
1
1
1
1
1
B7
1
B6
1
=+110
=+12710
=-12710
=-110
Range of Sign-Magnitude Numbers
A7
A6
A5
A4
A3
A2
A1
A0
0
0
0
0
0
0
0
1
B5
B4
B3
B2
B1
B0
B7
SIGN BIT
B6
0
1
1
1
1
1
1
1
A7
A6
A5
A4
A3
A2
A1
A0
1
0
0
0
0
0
0
1
B5
B4
B3
B2
B1
B0
1
1
1
1
1
1
B7
1
B6
1
=+110
=+12710
=-12710
=-110
การคอมพลีเมนต์ เลขฐานสอง
แบ่งออกเป็ น
 คอมพลีเมนต์ 1 (1’s complement)
 คอมพลีเมนต์ 2 (2’s complement)
 การคอมพลีเมนต์เลขฐานสองนี้ นาไปใช้เกี่ยวกับการคานวณทาง
ไมโครคอมพิวเตอร์มาก เพราะว่าจะใช้ในลักษณะการลบด้วย
วิธีการบวกด้วยคอมพลีเมนต์
 สรุ ป การลบด้วยการบวกด้วยคอมพลีเมนต์น้ น
ั จะทานองเดียวกับ
การคอมพลีเมนต์เลขฐานสิ บ
การคอมพลีเมนต์ เลขฐานสอง
X3X2X1X0 = 1000
1’s complement
X3X2X1X0 = 0111
X3
X2
X1
X0
X3
X2
X1
X0
2’s complement
2’s complement = 1’s complement + 1
Positive and Negative Numbers
1000 1001 1010 1011 1100 1101 1110 1111 0000 0001 0010 0011 0100 0101 0110 0111
-8 -7 -6 -5 -4 -3 -2 -1
0 +1 +2 +3 +4 +5 +6 +7
Magnitude
Positive
Negative
1
2
3
4
5
6
7
8
0001
0010
0011
0100
0101
0110
0111
-
1111
1110
1101
1100
1011
1010
1001
1000
2’ S-complement representation summary




Positive numbers always have a sign bit of 0, and
negative numbers always have a sign bit of 1.
Positive numbers are stored in sign-magnitude
form.
Negative numbers are stored as 2’s complements.
Taking the 2’s complement is equivalent to a sign
change.
Example :
Binary contents
Hexadecimal contents
Decimal contents
0001 0100
14H
+20
____ 1101
____
1101
DDH
___
-35
____ 1111
____
0010
___H
2F
+47
____ 1101
____
1011
BDH
___
-67
1001 1110
___H
9E
___
-98
____ 0000
____
0111
70H
___
+112
____ 0011
____
1000
___H
83
-125
____ 1110
____
0110
6EH
___
110
___ 0010
___ 1101
___ 1010
___
1011
_____H
B2DA
-19,750
2’s complement arithmetic
ADDITION
CASE 1 Both positive.
+83
+16
83
+16
99
0101 0011
0001 0000
0101 0011
+0001 0000
0110 0011
CASE 2 Positive and
smaller negative.
+125
-68
125
+(-68)
57
0111 1101
1011 1100
0111 1101
+1011 1100
1 0011 1001
CASE 3 Positive and larger
CASE 4 Both negative.
negative.
+37
-115
0010 0101
1000 1101
37
0010 0101
+(-115) +1000 1101
-78
1011 0010
-43
-78
1101 0101
1011 0010
-43
1101 0101
+(-78) +1011 0010
-121 1 1000 0111
2’s complement arithmetic
SUBTRACTION
CASE 1 Both positive.
0101 0011
+83
0001 0000
+16
83
0101 0011
+(-16) +1111 0000
67
1 0100 0011
CASE 2 Positive and
smaller negative.
+68
-27
68
+(+27)
95
0100 0100
1110 0101
0100 0100
+0001 1011
0101 1111
CASE 3 Positive and larger
CASE 4 Both negative.
negative.
+14
-108
0000 1110
1001 0100
14
0000 1110
+(+108) +0110 1100
122
0111 1010
-43
-78
-43
1101 0101
1011 0010
1101 0101
+(+78) +0100 1110
35 1 0010 0011
Controlled inverter
A7
A6
A5
A4
A3
A2
A1
A0
INVERT
Y7
Y6
INV
Y5
Y4
Y3
Y2
LOGIC
0
A7-A0
0110 1110
0
Y7-Y0
0110 1110
1
Y7-Y0
1001 0001
Y1
Y0
Binary adder-subtractor diagram
A7
B7
A6
B6
A5
B5
A4
B4
A3
B3
A2
B2
A1
B1
A0
B0
ADD/SUB
S8
S7
S6
S5
ADDITION
A7 A6 A5 A4 A3 A2 A1 A0
+B7 B6 B5 B4 B3 B2 B1 B0
S7 S6 S5 S4 S3 S2 S1 S0
S4
S3
S2
S1
S0
SUBTRACTION
A7 A6 A5 A4 A3 A2 A1 A0
- - - - - - - -
+B7 B6 B5 B4 B3 B2 B1 B0 +1
S7 S6 S5 S4 S3 S2 S1 S0
Binary adder-subtractor circuit.
ADD/
7483
7483