Escolar Documentos
Profissional Documentos
Cultura Documentos
Ricardo Pannain
pannainr@gmail.com
1
Conversão Decimal-Binária
2
Números em diferentes Bases
3
Projetar um circuito que gere o resultado e o carry out de
uma soma de dois números de 1 bit.
4
x 0 0 1 1
+y +0 +1 +0 +1
x y Sum Carry
c s 0 0 0 1 0 1 1 0
0 0 0 0
0 1 1 0 Carry Sum
1 0 1 0
(a) The four possible cases
1 1 0 1
Carry Sum
Sum = x XOR y x y c s
Carry = x . y 0 0 0 0
0 1 0 1
Meio Somador 1 0 0 1
(Half - adder) 1 1 1 0
x
s
y
x s
HA
y c
c
5
(c) Circuit (d) Graphical symbol
Adição Binária
6
Somador
Completo
(Full-adder)
OBS
S = x’ y’ c + x’ y c’ + x y c + x y’ c’ = x XOR y XOR c 7
OBS
S = x’ y’ c + x’ y c’ + x y c + x y’ c’ = x XOR y XOR c
8
Somador Completo (Full-adder)
9
xiyi
ci 00 01 11 10
0 1 1
ci xi yi ci +1 si
1 1 1
0 0 0 0 0
0 0 1 0 1
s i = x i y i c i
0 1 0 0 1
0 1 1 1 0 xiyi
1 0 0 0 1
ci 00 01 11 10
1 0 1 1 0
Somador 1
1
1
1
0
1
1
1
0
1
0 1
Completo 1 1 1 1
xi
yi si
ci
ci + 1
10
(c) Circuit
Projetar um somador de n-bits
11
Somador de n-bits – ripple carry
xn – 1 yn – 1 x1 y1 x0 y0
c1
cn FA cn ” 1 c2 FA FA c0
sn – 1 s1 s0
MSB position LSB position
12
Formatos para representação de números inteiros
b n–1
b1 b 0
Magnitude
MSB
bn – 1 bn – 2 b1 b0
Magnitude
Sign
0 denotes +
1 denotes – MSB
13
Números inteiros sinalizados com 4 bits
14
SM C1 C2
+7 -> 0111 0111 0111
s = a - b = a + (-b) = a+ (not b) + 1
15
Exemplos de adição em complemento de 1
(+ 5) 0101 – 5 1010
+ (+ 2) +0010 + (+ 2) +0010
(+ 7) 0111 - 3 1100
16
Exemplos de adição em complemento de 2
( + 5) 0101 –5 1011
+ ( + 2) + 0010 + ( + 2) + 0010
( + 7) 0111 –3 1101
( + 5) 0101 –5 1011
+ –2 + 1110 + –2 + 1110
( + 3) 1 0011 –7 11001
ignore ignore
s = a - b = a + (-b) = a+ (not b) + 1
s = 5 – 2 = 0101 + (1101 + 1) = 1 0011
17
Exemplos de subtração em complemento de 1
( + 5) 0101 0101
– ( + 2) – 0010 + 1110
( + 3) 10011
ignore
–5 1011 1011
– ( + 2) – 0010 + 1110
–7 11001
ignore
( + 5) 0101 0101
– –2 – 1110 + 0010
( + 7) 0111
–5 1011 1011
– –2 – 1110 + 0010
–3 1101
18
Interpretação Gráfica de números de 4 bits em
complemento de 2
0000
1111 0001
1110 0010
–1 0 +1
–2 +2
1101 0011
–3 +3
1100 –4 +4 0100
–5 +5
1011 0101
–6 +6
–7 –8 +7
1010 0110
1001 0111
1000
19
Projetar um circuito somador/subtrator
S = A – B = A + (-B) = A + B’ +1
20
Somador / Subtrator
yn – 1 y1 y0
Add Sub
control
xn – 1 x1 x0
cn n-bit adder c0
sn – 1 s1 s0
21
Exemplo de ocorrência de overflow
( + 7) 0111 –7 1001
+ ( + 2) + 0010 + ( + 2) + 0010
( + 9) 1001 –5 1011
c4 = 0 c4 = 0
c3 = 1 c3 = 0
1000
( + 7) 0111 –7 1001
+ – 2 + 1110 + –2 + 1110
( + 5) 1 0101 –9 10111
c4 = 1 c4 = 1
c3 = 1 c3 = 0
Ov = SxSySr’ + Sx’Sy’Sr
22
Calcular o tempo necessário para uma soma de 2 número de 4 bits,
em um somador ripple carry,
supondo que o atraso de uma porta seja t
xn – 1 yn – 1 x1 y1 x0 y0
c1
cn FA cn ” 1 c2 FA FA c0
sn – 1 s1 s0
MSB position LSB position
Full Adder
23
Calcular o tempo necessário para uma soma de 2 número de 4 bits,
supondo que o atraso de uma porta seja t
xn – 1 yn – 1 x1 y1 x0 y0
c1
cn FA cn ” 1 c2 FA FA c0
sn – 1 s1 s0
MSB position LSB position
s0 - >2t
c1 -> 2t
s1 -> 3t
c2 -> 4t
s2 -> 5t
c3 -> 6t
s3 -> 7t
c4 -> 8t 24
Somador ripple-carry com generação/propagação de
sinais
x1 y1 x0 y0
g1 p1 g0 p0
c1
c2 c0
Stage 1 Stage 0
s1 s0
25
Somador carry-lookahead
Como fazer com que um somador trabalhe
mais rápido ? Obs: gi = xiyi
pi = (xi + yi)
26
Somador carry-lookahead
Como fazer com que um somador trabalhe
mais rápido ? Obs: gi = xiyi
pi = (xi + yi)
27
Somador carry-lookahead
Como fazer com que um somador trabalhe
mais rápido ? Obs: g0 = x0y0
(x0 + y0)c0 = p0c0 -> p0 = x0 + y0
28
s0 2t
c1 = g0 + p0c0 3t
s1 4t Somador carry-lookahead
FANIN =3
c2 = g1 + p1g0 + p1p0c0 3t
s2 4t
c8
c32 Block c24 c16 Block Block c0
3 1 0
s31 – 24 s15 – 8 s7 – 0
30
Dois estágios de um somador carry-lookahead
x1 y1 x0 y0
x0 y0
g1 p1 g0 p0
c0
c2
c1
s1 s0
31
Esquemático usando um módulo LPM adder/subtractor
32
Resultado da simulação de um módulo LPM adder/subtrator
LIBRARY ieee ;
USE ieee.std_logic_1164.all ;
ENTITY fulladd IS
PORT ( Cin, x, y : IN STD_LOGIC ;
s, Cout : OUT STD_LOGIC ) ;
END fulladd ;
34
Código VHDL para um somador de 4 bits
LIBRARY ieee ;
USE ieee.std_logic_1164.all ;
ENTITY adder4 IS
PORT ( Cin : IN STD_LOGIC ;
x3, x2, x1, x0 : IN STD_LOGIC ;
y3, y2, y1, y0 : IN STD_LOGIC ;
s3, s2, s1, s0 : OUT STD_LOGIC ;
Cout : OUT STD_LOGIC ) ;
END adder4 ;
END Structure ; 35
Declaração de um Package
LIBRARY ieee ;
USE ieee.std_logic_1164.all ;
PACKAGE fulladd_package IS
COMPONENT fulladd
PORT ( Cin, x, y : IN STD_LOGIC ;
s, Cout : OUT STD_LOGIC ) ;
END COMPONENT ;
END fulladd_package ;
36
Usando um package para somador de 4 bits
LIBRARY ieee ;
USE ieee.std_logic_1164.all ;
USE work.fulladd_package.all ;
ENTITY adder4 IS
PORT ( Cin : IN STD_LOGIC ;
x3, x2, x1, x0 : IN STD_LOGIC ;
y3, y2, y1, y0 : IN STD_LOGIC ;
s3, s2, s1, s0 : OUT STD_LOGIC ;
Cout : OUT STD_LOGIC ) ;
END adder4 ;
ENTITY adder4 IS
PORT ( Cin : IN STD_LOGIC ;
X, Y : IN STD_LOGIC_VECTOR(3 DOWNTO 0) ;
S : OUT STD_LOGIC_VECTOR(3 DOWNTO 0) ;
Cout : OUT STD_LOGIC ) ;
END adder4 ;
38
Código VHDL code para um somador de 16-bit
LIBRARY ieee ;
USE ieee.std_logic_1164.all ;
USE ieee.std_logic_signed.all ;
ENTITY adder16 IS
PORT ( X, Y : IN STD_LOGIC_VECTOR(15 DOWNTO 0) ;
S : OUT STD_LOGIC_VECTOR(15 DOWNTO 0) ) ;
END adder16 ;
39
Somador de 16-bit com carry e overflow
LIBRARY ieee ;
USE ieee.std_logic_1164.all ;
USE ieee.std_logic_signed.all ;
ENTITY adder16 IS
PORT ( Cin : IN STD_LOGIC ;
X, Y : IN STD_LOGIC_VECTOR(15 DOWNTO 0) ;
S : OUT STD_LOGIC_VECTOR(15 DOWNTO 0) ;
Cout, Overflow : OUT STD_LOGIC ) ;
END adder16 ;
LIBRARY ieee ;
USE ieee.std_logic_1164.all ;
USE ieee.std_logic_arith.all ;
ENTITY adder16 IS
PORT ( Cin : IN STD_LOGIC ;
X, Y : IN SIGNED(15 DOWNTO 0) ;
S : OUT SIGNED(15 DOWNTO 0) ;
Cout, Overflow : OUT STD_LOGIC ) ;
END adder16 ;
ENTITY adder16 IS
PORT ( X, Y : IN INTEGER RANGE -32768 TO 32767 ;
S : OUT INTEGER RANGE -32768 TO 32767 ) ;
END adder16 ;
42
10
x 10
___
00
10
------
0100
43
Circuito multiplicador 4 X 4
44
Circuito multiplicador 4 X 4
45
Circuito multiplicador 4 X 4
0 m3 m2 m1 m0
q0
0
PP1
q1
q2
0
PP2
q3
0
p7 p6 p5 p4 p3 p2 p1 p0
mk + 1 mk
Bit of PPi mk
q0
q1 qj
c out FA c in c out FA c in
(b) A block in the top row (c) A block in the bottom two rows
46
Circuito multiplicador 4 X 4
0 m3 m2 m1 m0
q0
0
PP1
q1
q2
0
PP2
q3
0
p7 p6 p5 p4 p3 p2 p1 p0
47
Circuito multiplicador 4 X 4
mk + 1 mk
Bit of PPi mk
q0
q1 qj
c out FA c in c out FA c in
(b) A block in the top row (c) A block in the bottom two rows
48
Multiplicação de números sinalizados
49
Multiplicação de números sinalizados
50
Padrão IEEE 754 standard número de ponto flutuante
N = (-1)S x 1,M x 2 exp
E = exp + 127
32 bits
S E M
Sign
0 denotes + 8-bit 23 bits of mantissa
1 denotes – excess-127
exponent
(a) Single precision
E = exp + 1023
64 bits
S E M
Sign
11-bit excess-1023 52 bits of mantissa
exponent
(c) Double precision
51
Representar -5,010 no padrão IEEE 754
-5,010 = - 101,02 x 20 = -1,0100 x 22
N = (-1)S x 1,M x 2 exp
N = (-1)1 x 101,00 x 20 =
N = (-1)1 x 1,0100 x 22 =
E = 2 + 127 = 129
1 10000001 0100000000000..00
32 bits
S E M
Sign
0 denotes + 8-bit 23 bits of mantissa
1 denotes – excess-127
exponent
(a) Single precision
52
N = (-1)S x 1,M x 2 exp
32 bits
S E M
Sign
0 denotes + 8-bit 23 bits of mantissa
1 denotes – excess-127
exponent
(a) Single precision
53
Código BCD – Binary Code Decimal
54
Adição em BCD
S=2
X 1000 8
+ Y + 1001 + 9
Z 10001 17
+ 0110
carry 10111
S=7
55
1010
1011
1100
1101
1110
1111
56
Exercício: Projetar um somador BCD de um dígito (blocos)
1010
1011
1100
1101
1110
1111
10000
1........
57
0101 1000
0110 1001
1011 10001
0110 0110
1 0001 1 0111
58
Somador BCD de um dígito – diagrama de blocos
X Y
c in
4-bit adder
carry-out
Detect if
sum > 9
6 0
MUX
Adjust
59
S
011 1 010 0
x3 x 2 x1 x 0 y 3 y2 y1 y0
z3 z2 z1 z0
1 0 1 1
1 1
Two-bit adder
cout s3 s2 s1 s0
60
Circuito para um somador BCD de um dígito
Somador BCD de um dígito – código VHDL
LIBRARY ieee ;
USE ieee.std_logic_1164.all ;
USE ieee.std_logic_unsigned.all ;
ENTITY BCD IS
PORT ( X, Y : IN STD_LOGIC_VECTOR(3 DOWNTO 0) ;
S : OUT STD_LOGIC_VECTOR(4 DOWNTO 0) ) ;
END BCD ;
61
Simulação de um somador BCD de um dígito
62
63