39
MO401 5.1 2006 Prof. Paulo Cesar Centoducatte [email protected] www.ic.unicamp.br/~ducatte MC542 Organização de Computadores Teoria e Prática

MO401 5.1 2006 Prof. Paulo Cesar Centoducatte [email protected] ducatte MC542 Organização de Computadores Teoria e Prática

Embed Size (px)

Citation preview

Page 1: MO401 5.1 2006 Prof. Paulo Cesar Centoducatte ducatte@ic.unicamp.br ducatte MC542 Organização de Computadores Teoria e Prática

MO401 5.1

2006

Prof. Paulo Cesar Centoducatte

[email protected]

www.ic.unicamp.br/~ducatte

MC542

Organização de ComputadoresTeoria e Prática

Page 2: MO401 5.1 2006 Prof. Paulo Cesar Centoducatte ducatte@ic.unicamp.br ducatte MC542 Organização de Computadores Teoria e Prática

MO401 5.2

MC542

Circuitos Lógicos

Circuitos CombinacionáisBlocos Básicos

“Fundamentals of Digital Logic with VHDL Design” - (Capítulo 6)

Page 3: MO401 5.1 2006 Prof. Paulo Cesar Centoducatte ducatte@ic.unicamp.br ducatte MC542 Organização de Computadores Teoria e Prática

MO401 5.3

Circuitos Combinacionáis: Blocos Básicos Sumário

• Multiplexador– Implementação de Funções Lógicas Usando Mux

• Decodificador• Codificador• Codificador de Prioridade• Conversores • Comparador• VHDL para Circuito Combinacional

– Select– Atribuição Condicional– Processos

» If-Then-Else» Case

Page 4: MO401 5.1 2006 Prof. Paulo Cesar Centoducatte ducatte@ic.unicamp.br ducatte MC542 Organização de Computadores Teoria e Prática

MO401 5.4

Multiplexador: 2 para 1 (2:1)

Tabela Verdade

01

fs

w0w1

transmission gates

w 0

w 1 f

s

Símbolo Gráfico

f

s

w0w1

01

fs

w0

w1

Suma-de-produtos

Page 5: MO401 5.1 2006 Prof. Paulo Cesar Centoducatte ducatte@ic.unicamp.br ducatte MC542 Organização de Computadores Teoria e Prática

MO401 5.5

Multiplexador: 4 para 1 (4:1)

f

s 1

w 0

w 1

00

01

s 0

w 2

w 3

10

11

w 0

w 1

0

0

1

1

1

0

1

f s 1

0

s 0

w 2

w 3

f

s 1

w 0

w 1

s 0

w 2

w 3

Page 6: MO401 5.1 2006 Prof. Paulo Cesar Centoducatte ducatte@ic.unicamp.br ducatte MC542 Organização de Computadores Teoria e Prática

MO401 5.6

Mux 4:1 a partir de Mux 2:1

0

w 0

w 1

0

1

w 2

w 3

0

1

f 0

1

s 1

s

Page 7: MO401 5.1 2006 Prof. Paulo Cesar Centoducatte ducatte@ic.unicamp.br ducatte MC542 Organização de Computadores Teoria e Prática

MO401 5.7

Mux 16:1

w 8

w 11

s 1

w 0

s 0

w 3

w 4

w 7

w 12

w 15

s 3

s 2

f

Page 8: MO401 5.1 2006 Prof. Paulo Cesar Centoducatte ducatte@ic.unicamp.br ducatte MC542 Organização de Computadores Teoria e Prática

MO401 5.8

Exemplo de Uso de Mux 2x2 crossbar switch

x 1 x 2

y 1 y 2

s

x 1 0

1

x 2 0

1

s

y 1

y 2

Page 9: MO401 5.1 2006 Prof. Paulo Cesar Centoducatte ducatte@ic.unicamp.br ducatte MC542 Organização de Computadores Teoria e Prática

MO401 5.9

Síntese de Funções Lógicas Usando MUX

0

1

0

0

1

1

1

0

1

f w 1

0

w 2

1

0

f

w 1

0

1

w 2

1

0

0

1

0

0

1

1

1

0

1

f w 1

0

w 2

1

0

0

1

f w 1

w 2

w 2

f

w 2

w 1

Page 10: MO401 5.1 2006 Prof. Paulo Cesar Centoducatte ducatte@ic.unicamp.br ducatte MC542 Organização de Computadores Teoria e Prática

MO401 5.10

Exemplo

w3

w3

000

11

1

01

fw1

0

w2

1

0 0

0 1

1 0

1 1

0

0

0

1

0 0

0 1

1 0

1 1

0

1

1

1

w1 w2 w3 f

0

0

0

0

1

1

1

1

f

w1

0

w2

1

w3

Page 11: MO401 5.1 2006 Prof. Paulo Cesar Centoducatte ducatte@ic.unicamp.br ducatte MC542 Organização de Computadores Teoria e Prática

MO401 5.11

Exempo

0 0

0 1

1 0

1 1

0

1

1

0

0 0

0 1

1 0

1 1

1

0

0

1

w1 w2 w3 f

0

0

0

0

1

1

1

1

w2 w3

w2 w3

f

w3

w1

w2

Page 12: MO401 5.1 2006 Prof. Paulo Cesar Centoducatte ducatte@ic.unicamp.br ducatte MC542 Organização de Computadores Teoria e Prática

MO401 5.12

Exemplo

f

w 1

w 2

w 3

0 0

0 1

1 0

1 1

0

1

1

0

0 0

0 1

1 0

1 1

1

0

0

1

w 1

w 2

w 3

f

0

0

0

0

1

1

1

1

w 3

w 3

w 3

w 3

Page 13: MO401 5.1 2006 Prof. Paulo Cesar Centoducatte ducatte@ic.unicamp.br ducatte MC542 Organização de Computadores Teoria e Prática

MO401 5.13

ExemploMaioria de uns

0 0

0 1

1 0

1 1

0

0

0

1

0 0

0 1

1 0

1 1

0

1

1

1

w 1

w 2

w 3

f

0

0

0

0

1

1

1

1

0

1

f w 1

w 2 w

3

w 2

w 3

+

f

w 3

w 1 w

2

Page 14: MO401 5.1 2006 Prof. Paulo Cesar Centoducatte ducatte@ic.unicamp.br ducatte MC542 Organização de Computadores Teoria e Prática

MO401 5.14

ExemploMaioria de uns

(a) Using a 2-to-1 multiplexer

f

w 2

w 1

w 3

f

w 1

w 2

w 3

(b) Using a 4-to-1 multiplexer

1

Page 15: MO401 5.1 2006 Prof. Paulo Cesar Centoducatte ducatte@ic.unicamp.br ducatte MC542 Organização de Computadores Teoria e Prática

MO401 5.15

Decodificador

0

w n 1 –

n

inputs

EnEnable

2 n

outputs

y 0

y 2 n 1 –

w

Page 16: MO401 5.1 2006 Prof. Paulo Cesar Centoducatte ducatte@ic.unicamp.br ducatte MC542 Organização de Computadores Teoria e Prática

MO401 5.16

Decodicifador 2:4

0

0

1

1

1

0

1

y 0

w 1

0

w 0

x x

1

1

0

1

1

En

0

0

0

1

0

y 1

1

0

0

0

0

y 2

0

1

0

0

0

y 3

0

0

1

0

0

w 0

En

y 0 w 1 y 1

y 2 y 3

w 1

w 0

y 0

y 1

y 2

y 3

En

Page 17: MO401 5.1 2006 Prof. Paulo Cesar Centoducatte ducatte@ic.unicamp.br ducatte MC542 Organização de Computadores Teoria e Prática

MO401 5.17

Decodicifador 3:8 Usando 2:4

w 2

w 0 y 0

y 1

y 2

y 3

w 0

En

y 0

w 1 y 1

y 2

y 3

w 0

En

y 0

w 1 y 1

y 2

y 3

y 4

y 5

y 6

y 7

w 1

En

Page 18: MO401 5.1 2006 Prof. Paulo Cesar Centoducatte ducatte@ic.unicamp.br ducatte MC542 Organização de Computadores Teoria e Prática

MO401 5.18

Decodicifador 4:16 Usando 2:4

w 0

En

y 0 w 1 y 1

y 2 y 3

y 8 y 9 y 10y 11

w 2

w 0 y 0 y 1 y 2 y 3

w 0

En

y 0 w 1 y 1

y 2 y 3

w 0

En

y 0 w 1 y 1

y 2 y 3

y 4 y 5 y 6 y 7

w 1

w 0

En

y 0 w 1 y 1

y 2 y 3

y 12y 13y 14y 15

w 0

En

y 0 w 1 y 1

y 2 y 3

w 3

En

Page 19: MO401 5.1 2006 Prof. Paulo Cesar Centoducatte ducatte@ic.unicamp.br ducatte MC542 Organização de Computadores Teoria e Prática

MO401 5.19

Memória 2m x n read-only memory (ROM)

Sel 2

Sel 1

Sel 0

Sel 2 m 1 –

Address

Read

d 0 d n 1 – d n 2 –

m -to-2

m

d

ecod

er

0/1 0/1 0/1

0/1 0/1 0/1

0/1 0/1 0/1

0/1 0/1 0/1

Data

a 0 a 1

a m 1 –

Page 20: MO401 5.1 2006 Prof. Paulo Cesar Centoducatte ducatte@ic.unicamp.br ducatte MC542 Organização de Computadores Teoria e Prática

MO401 5.20

Codificador

2n-to-n binary encoder

2 n

inputs

w 0

w 2 n 1 –

y 0

y n 1 –

n

outputs

Page 21: MO401 5.1 2006 Prof. Paulo Cesar Centoducatte ducatte@ic.unicamp.br ducatte MC542 Organização de Computadores Teoria e Prática

MO401 5.21

Codificador Binário 4:2

0

0

1

1

1

0

1

w 3

y 1

0

y 0

0

0

1

0

w 2

0

1

0

0

w 1

1

0

0

0

w 0

0

0

0

1

w 1

w 0

y 0

w 2

w 3

y 1

Page 22: MO401 5.1 2006 Prof. Paulo Cesar Centoducatte ducatte@ic.unicamp.br ducatte MC542 Organização de Computadores Teoria e Prática

MO401 5.22

Codificador de Prioridade

d

0

0

1

0

1

0

w0

y1

d

y0

1 1

0

1

1

1

1

z

1

x

x

0

x

w1

0

1

x

0

x

w2

0

0

1

0

x

w3

0

0

0

0

1

Exercício: Qual o Circuito Lógico?

Page 23: MO401 5.1 2006 Prof. Paulo Cesar Centoducatte ducatte@ic.unicamp.br ducatte MC542 Organização de Computadores Teoria e Prática

MO401 5.23

Conversor BCD para Código Display de 7 segmentos

1 0

1 1

1

1 1

w 0 a

1

b

0 1

1 1

1

0 1

1

0 1

0

0

w 1

0

1 1

0

0

w 2

0

0 0

0

1

w 3

0

0 0

0

0

c

1 0

1

0

0 1

1

0

1 1

1

0

0 0

0

1 1 0 0 1

1 1 1

1

0 1

1

0

1 1

1 1

1

1

1

0 1 1

1

d

0

1 0

0

1 0

e

1 0 1

1

1

0 1

0

0 1

0 0 0

1

f

1

0 0

1

1 1

g

1 0 1

1

1

1 1

1

0 1

w 0

a

w 1

b c d w 2

w 3 e f g

c e

a

g

b f

d

Display 7-segmentos

Page 24: MO401 5.1 2006 Prof. Paulo Cesar Centoducatte ducatte@ic.unicamp.br ducatte MC542 Organização de Computadores Teoria e Prática

MO401 5.24

Comparador de 4 bits

i 0

i 1

i 2

i 3

b 0

a 0

b 1

a 1

b 2

a 2

b 3

a 3

AeqB

AgtB

AltB

Page 25: MO401 5.1 2006 Prof. Paulo Cesar Centoducatte ducatte@ic.unicamp.br ducatte MC542 Organização de Computadores Teoria e Prática

MO401 5.25

Circuito CombinacionalVHDL

• Comandos de Atribuição:– Mux 2:1 - Comando Select

LIBRARY ieee ;USE ieee.std_logic_1164.all ;

ENTITY mux2to1 ISPORT (w0, w1, s : IN STD_LOGIC ;

f : OUT STD_LOGIC ) ;END mux2to1 ;

ARCHITECTURE Behavior OF mux2to1 ISBEGIN

WITH s SELECTf <= w0 WHEN '0',

w1 WHEN OTHERS ;END Behavior ;

Page 26: MO401 5.1 2006 Prof. Paulo Cesar Centoducatte ducatte@ic.unicamp.br ducatte MC542 Organização de Computadores Teoria e Prática

MO401 5.26

Circuito CombinacionalVHDL

• Mux 4:1 – Comando Select

LIBRARY ieee ;USE ieee.std_logic_1164.all ;

ENTITY mux4to1 ISPORT ( w0, w1, w2, w3 : IN STD_LOGIC ;

s : IN STD_LOGIC_VECTOR(1 DOWNTO 0) ;f : OUT STD_LOGIC ) ;

END mux4to1 ;

ARCHITECTURE Behavior OF mux4to1 ISBEGIN

WITH s SELECTf <= w0 WHEN "00",

w1 WHEN "01",w2 WHEN "10",w3 WHEN OTHERS ;

END Behavior ;

Page 27: MO401 5.1 2006 Prof. Paulo Cesar Centoducatte ducatte@ic.unicamp.br ducatte MC542 Organização de Computadores Teoria e Prática

MO401 5.27

Circuito CombinacionalVHDL

• Mux 4:1 - Como um Componente

LIBRARY ieee ;USE ieee.std_logic_1164.all ;

PACKAGE mux4to1_package ISCOMPONENT mux4to1

PORT ( w0, w1, w2, w3 : IN STD_LOGIC ;s : IN STD_LOGIC_VECTOR(1 DOWNTO 0) ;f : OUT STD_LOGIC ) ;

END COMPONENT ;END mux4to1_package ;

Page 28: MO401 5.1 2006 Prof. Paulo Cesar Centoducatte ducatte@ic.unicamp.br ducatte MC542 Organização de Computadores Teoria e Prática

MO401 5.28

• Mux 16:1 usando o Componente Mux 4:1

LIBRARY ieee ;USE ieee.std_logic_1164.all ;LIBRARY work ;USE work.mux4to1_package.all ;

ENTITY mux16to1 ISPORT ( w : IN STD_LOGIC_VECTOR(0 TO 15) ;

s : IN STD_LOGIC_VECTOR(3 DOWNTO 0) ;f : OUT STD_LOGIC ) ;

END mux16to1 ;

ARCHITECTURE Structure OF mux16to1 ISSIGNAL m : STD_LOGIC_VECTOR(0 TO 3) ;

BEGINMux1: mux4to1 PORT MAP ( w(0), w(1), w(2), w(3), s(1 DOWNTO 0), m(0) ) ;Mux2: mux4to1 PORT MAP ( w(4), w(5), w(6), w(7), s(1 DOWNTO 0), m(1) ) ;Mux3: mux4to1 PORT MAP ( w(8), w(9), w(10), w(11), s(1 DOWNTO 0), m(2) ) ;Mux4: mux4to1 PORT MAP ( w(12), w(13), w(14), w(15), s(1 DOWNTO 0), m(3) ) ;Mux5: mux4to1 PORT MAP

( m(0), m(1), m(2), m(3), s(3 DOWNTO 2), f ) ;END Structure ;

Page 29: MO401 5.1 2006 Prof. Paulo Cesar Centoducatte ducatte@ic.unicamp.br ducatte MC542 Organização de Computadores Teoria e Prática

MO401 5.29

Decodificador Binário

LIBRARY ieee ;USE ieee.std_logic_1164.all ;

ENTITY dec2to4 ISPORT ( w : IN STD_LOGIC_VECTOR(1 DOWNTO 0) ;

En : IN STD_LOGIC ;y : OUT STD_LOGIC_VECTOR(0 TO 3) ) ;

END dec2to4 ;

ARCHITECTURE Behavior OF dec2to4 ISSIGNAL Enw : STD_LOGIC_VECTOR(2 DOWNTO 0) ;

BEGINEnw <= En & w ;WITH Enw SELECT

y <= "1000" WHEN "100","0100" WHEN "101","0010" WHEN "110","0001" WHEN "111","0000" WHEN OTHERS ;

END Behavior ;

Page 30: MO401 5.1 2006 Prof. Paulo Cesar Centoducatte ducatte@ic.unicamp.br ducatte MC542 Organização de Computadores Teoria e Prática

MO401 5.30

Circuito CombinacionalVHDL

• Mux 2:1 Comando Condicional

LIBRARY ieee ;USE ieee.std_logic_1164.all ;

ENTITY mux2to1 ISPORT ( w0, w1, s : IN STD_LOGIC ;

f : OUT STD_LOGIC ) ;END mux2to1 ;

ARCHITECTURE Behavior OF mux2to1 ISBEGIN

f <= w0 WHEN s = '0' ELSE w1 ;END Behavior ;

Page 31: MO401 5.1 2006 Prof. Paulo Cesar Centoducatte ducatte@ic.unicamp.br ducatte MC542 Organização de Computadores Teoria e Prática

MO401 5.31

Circuito CombinacionalVHDL• Processo (mux 2:1)

– Comando IF-Then-Else

LIBRARY ieee ;USE ieee.std_logic_1164.all ;

ENTITY mux2to1 ISPORT ( w0, w1, s : IN STD_LOGIC ;

f : OUT STD_LOGIC ) ;END mux2to1 ;

ARCHITECTURE Behavior OF mux2to1 ISBEGIN

PROCESS ( w0, w1, s )BEGIN

IF s = '0' THENf <= w0 ;

ELSEf <= w1 ;

END IF ;END PROCESS ;

END Behavior ;

Page 32: MO401 5.1 2006 Prof. Paulo Cesar Centoducatte ducatte@ic.unicamp.br ducatte MC542 Organização de Computadores Teoria e Prática

MO401 5.32

Circuito CombinacionalVHDL

• Processo (mux 2:1 – alternativo)

LIBRARY ieee ;USE ieee.std_logic_1164.all ;

ENTITY mux2to1 ISPORT ( w0, w1, s : IN STD_LOGIC ;

f : OUT STD_LOGIC ) ;END mux2to1 ;

ARCHITECTURE Behavior OF mux2to1 ISBEGIN

PROCESS ( w0, w1, s )BEGIN

f <= w0 ;IF s = '1' THEN

f <= w1 ;END IF ;

END PROCESS ;END Behavior ;

Page 33: MO401 5.1 2006 Prof. Paulo Cesar Centoducatte ducatte@ic.unicamp.br ducatte MC542 Organização de Computadores Teoria e Prática

MO401 5.33

Exercício: Qual o Bloco implementado?

LIBRARY ieee ;USE ieee.std_logic_1164.all ;ENTITY priority IS

PORT ( w : IN STD_LOGIC_VECTOR(3 DOWNTO 0) ;y : OUT STD_LOGIC_VECTOR(1 DOWNTO 0) ;z : OUT STD_LOGIC ) ;

END priority ;

ARCHITECTURE Behavior OF xxxxxxx? ISBEGINPROCESS ( w )BEGIN

IF w(3) = '1' THENy <= "11" ;

ELSIF w(2) = '1' THEN y <= "10" ;

ELSIF w(1) = '1' THENy <= "01" ;

ELSEy <= "00" ;

END IF ;END PROCESS ;z <= '0' WHEN w = "0000" ELSE '1' ;

END Behavior ;

Page 34: MO401 5.1 2006 Prof. Paulo Cesar Centoducatte ducatte@ic.unicamp.br ducatte MC542 Organização de Computadores Teoria e Prática

MO401 5.34

Circuito CombinacionalVHDL• Processo (Comando Case)

LIBRARY ieee ;USE ieee.std_logic_1164.all ;

ENTITY mux2to1 ISPORT ( w0, w1, s : IN STD_LOGIC ;

f : OUT STD_LOGIC ) ;END mux2to1 ;

ARCHITECTURE Behavior OF mux2to1 ISBEGIN

PROCESS ( w0, w1, s )BEGIN

CASE s ISWHEN '0' =>

f <= w0 ;WHEN OTHERS =>

f <= w1 ;END CASE ;

END PROCESS ;END Behavior ;

Page 35: MO401 5.1 2006 Prof. Paulo Cesar Centoducatte ducatte@ic.unicamp.br ducatte MC542 Organização de Computadores Teoria e Prática

MO401 5.35

LIBRARY ieee ;USE ieee.std_logic_1164.all ;ENTITY seg7 IS

PORT ( bcd : IN STD_LOGIC_VECTOR(3 DOWNTO 0) ;leds : OUT STD_LOGIC_VECTOR(1 TO 7) ) ;

END seg7 ;ARCHITECTURE Behavior OF seg7 ISBEGIN

PROCESS ( bcd )BEGIN

CASE bcd IS -- abcdefgWHEN "0000" => leds <= "1111110" ;WHEN "0001" => leds <= "0110000" ;WHEN "0010" => leds <= "1101101" ;WHEN "0011" => leds <= "1111001" ;WHEN "0100" => leds <= "0110011" ;WHEN "0101" => leds <= "1011011" ;WHEN "0110" => leds <= "1011111" ;WHEN "0111" => leds <= "1110000" ;WHEN "1000" => leds <= "1111111" ;WHEN "1001" => leds <= "1110011" ;WHEN OTHERS => leds <= "-------" ;

END CASE ;END PROCESS ;

END Behavior ;

Decodificadorde 7 segmentos

Page 36: MO401 5.1 2006 Prof. Paulo Cesar Centoducatte ducatte@ic.unicamp.br ducatte MC542 Organização de Computadores Teoria e Prática

MO401 5.36

74381 ALU

Page 37: MO401 5.1 2006 Prof. Paulo Cesar Centoducatte ducatte@ic.unicamp.br ducatte MC542 Organização de Computadores Teoria e Prática

MO401 5.37

74381 ALU

LIBRARY ieee ;USE ieee.std_logic_1164.all ;USE ieee.std_logic_unsigned.all ;

ENTITY alu ISPORT ( s : IN STD_LOGIC_VECTOR(2 DOWNTO 0) ;

A, B : IN STD_LOGIC_VECTOR(3 DOWNTO 0) ;F : OUT STD_LOGIC_VECTOR(3 DOWNTO 0) ) ;

END alu ;

Page 38: MO401 5.1 2006 Prof. Paulo Cesar Centoducatte ducatte@ic.unicamp.br ducatte MC542 Organização de Computadores Teoria e Prática

MO401 5.38

74381 ALUARCHITECTURE Behavior OF alu ISBEGIN

PROCESS ( s, A, B )BEGIN

CASE s ISWHEN "000" =>

F <= "0000" ;WHEN "001" =>

F <= B - A ;WHEN "010" =>

F <= A - B ;WHEN "011" =>

F <= A + B ;WHEN "100" =>

F <= A XOR B ;WHEN "101" =>

F <= A OR B ;WHEN "110" =>

F <= A AND B ;WHEN OTHERS =>

F <= "1111" ;END CASE ;

END PROCESS ;END Behavior ;

Page 39: MO401 5.1 2006 Prof. Paulo Cesar Centoducatte ducatte@ic.unicamp.br ducatte MC542 Organização de Computadores Teoria e Prática

MO401 5.39

74381 ALU