Professional Documents
Culture Documents
PELOTAS
Departamento de Engenharia de Computação
Junho
2018
UNIVERSIDADE CATÓLICA DE
PELOTAS
Departamento de Engenharia de Computação
Relatório
Junho
2018
Conteúdo
1 Introdução 1
2 Objetivo 2
3 Metodologia 3
13 Conclusão 26
Bibliografia 27
1 Introdução
O trabalho tem como objetivo o desenvolvimento de um código na lingua-
gem de descrição de hardware VHDL (Very High Speed Integrated Circuits
Hardware Description Language), visando uma estrutura de escrita e leitura
da memória de dados do processador MIPS, com o uso de barramento de 16
bits, onde uma implementação do MIPS básica possui instruções de referência
a memória load word (LW - lê da memória) e store word (SW - escrita na
memória), instruções lógicas e aritméticas como adição, subtração.
1
2 Objetivo
Desenvolver em linguagem de descrição de hardware VHDL, uma estru-
tura para escrita e leitura na memória de dados do processador MIPS uti-
lizando barramento de 16 bits. A arquitetura deve conter um estágio de
pipeline entre o banco de registradores e a ULA, de acordo com a figura
abaixo:
2
3 Metodologia
A metodologia aplicada nesse trabalho consiste em construir cada bloco
de código separadamente, afim de uni-los com um bloco integrador de si-
nal, todos os blocos levam em conta um barramento de 16 bits. A seguir
cada seção apresenta-rá seu respectivo código na linguagem VHDL e sua
Simulação.
3
4 Código em VHDL - Módulo Registrador 16
bits
O código abaixo demonstra um registrador de 16 bits, com 3 sinais de
entrada(CLOCK, ENABLE, REG1) e um sinal de saı́da (Sreg1). Registrador
16 Bits.
LIBRARY i e e e ;
USE i e e e . s t d l o g i c 1 1 6 4 . a l l ;
ENTITY R e g i s t r a d o r 1 6 B i t s IS
PORT (
clk , enable : IN s t d l o g i c ;
reg1 : IN s t d l o g i c v e c t o r ( 1 5 downto 0 ) ;
S re g1 : OUT s t d l o g i c v e c t o r ( 1 5 downto 0 )
);
END R e g i s t r a d o r 1 6 B i t s ;
ARCHITECTURE r e g i s t r a d o r OF R e g i s t r a d o r 1 6 B i t s IS
BEGIN
PROCESS( c l k , e n a b l e )
BEGIN
IF ( c l k ’EVENT AND c l k = ’ 1 ’ ) THEN
i f ( e n a b l e = ’ 1 ’ ) then
Sreg1 <= r e g 1 ;
else
Sreg1 <= ” 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ” ;
end i f ;
END IF ;
END PROCESS;
END a r c h i t e c t u r e ;
4
Figura 2: Exemplo Simulação Registrador 16 bits
Registrador16x16
LIBRARY i e e e ;
USE i e e e . s t d l o g i c 1 1 6 4 . a l l ;
ENTITY Mux21com16bits IS
PORT (
s e l : in s t d l o g i c ;
a , b : IN STD LOGIC vector (1 5 downto 0 ) ;
y : OUT STD LOGIC vector (1 5 downto 0 ) ) ;
END Mux21com16bits ;
ARCHITECTURE M u l t i p l e x a d o r OF Mux21com16bits IS
BEGIN
WITH s e l SELECT
y <= a WHEN ’ 0 ’ ,
b WHEN OTHERS;
END a r c h i t e c t u r e ;
5
Figura 3: Exemplo Simulação Registrador 16X16
6
5 Código em VHDL - Módulo Decodificador
library ieee ;
us e i e e e . s t d l o g i c 1 1 6 4 . a l l ;
entity Decodificador i s
port (
endereco : i n s t d l o g i c v e c t o r ( 3 downto 0 ) ;
s : out s t d l o g i c v e c t o r ( 1 5 downto 0 )
);
end D e c o d i f i c a d o r ;
with e n d e r e c o s e l e c t
end c i r c u i t o ;
7
Figura 5: Exemplo Simulação Decodificador 16 Bits
LIBRARY i e e e ;
USE i e e e . s t d l o g i c 1 1 6 4 . a l l ;
ENTITY Mux2X1 IS
PORT (
s e l : in s t d l o g i c ;
b : IN STD LOGIC vector ( 15 downto 0 ) ;
s : OUT STD LOGIC vector (1 5 downto 0 ) ) ;
END Mux2X1 ;
ARCHITECTURE M u l t i p l e x a d o r OF Mux2X1 IS
BEGIN
END a r c h i t e c t u r e ;
8
Figura 6: Exemplo Simulação Mux2x1
9
Mux 4X1:
LIBRARY i e e e ;
USE i e e e . s t d l o g i c 1 1 6 4 . a l l ;
ENTITY Mux4X1 IS
PORT (
s e l : in s t d l o g i c v e c t o r ( 1 downto 0 ) ;
s i n 1 , s i n 2 , s i n 3 , s l t : IN STD LOGIC vector ( 1 5 downto 0 ) ;
s : OUT STD LOGIC vector (1 5 downto 0 ) ) ;
END Mux4X1 ;
s <= s i n 1 WHEN ” 0 0 ” ,
s i n 2 WHEN ” 0 1 ” ,
s i n 3 WHEN ” 1 0 ” ,
s l t WHEN OTHERS;
END a r c h i t e c t u r e ;
10
Mux 16X1:
LIBRARY i e e e ;
USE i e e e . s t d l o g i c 1 1 6 4 . a l l ;
ENTITY Mux16X1 IS
PORT (
s e l : in s t d l o g i c v e c t o r ( 3 downto 0 ) ;
reg0 , reg1 , reg2 , reg3 , reg4 , reg5 , reg6 , reg7 , reg8 ,
ARCHITECTURE M u l t i p l e x a d o r OF Mux16X1 IS
BEGIN WITH s e l SELECT
s <= r e g 0 WHEN ” 000 0” ,
reg1 WHEN ” 000 1” ,
reg2 WHEN ” 001 0” ,
reg3 WHEN ” 001 1” ,
reg4 WHEN ” 010 0” ,
reg5 WHEN ” 010 1” ,
reg6 WHEN ” 011 0” ,
reg7 WHEN ” 011 1” ,
reg8 WHEN ” 100 0” ,
reg9 WHEN ” 100 1” ,
reg10 WHEN ”1 010 ” ,
reg11 WHEN ”1 011 ” ,
reg12 WHEN ”1 100 ” ,
reg13 WHEN ”1 101 ” ,
reg14 WHEN ”1 110 ” ,
reg15 WHEN OTHERS;
END a r c h i t e c t u r e ;
11
Figura 8: Exemplo Simulação Mux16x1
library ieee ;
us e i e e e . s t d l o g i c 1 1 6 4 . a l l ;
e n t i t y ram i s g e n e r i c (
b i t s : i n t e g e r := 1 6 ;
l i n h a s : i n t e g e r := 16 s ) ;
port (
e n a bl e , c l k : in s t d l o g i c ;
endereco : i n i n t e g e r range 0 t o l i n h a s −1;
dados : i n s t d l o g i c v e c t o r ( b i t s −1 downto 0 ) ;
s: out s t d l o g i c v e c t o r ( b i t s −1 downto 0 ) ) ;
end ram ;
a r c h i t e c t u r e memoria o f ram i s
type v e c t o r a r r a y i s a r r a y ( 0 t o l i n h a s −1) o f
s t d l o g i c v e c t o r ( b i t s −1 downto 0 ) ;
s i g n a l memoria : v e c t o r a r r a y ;
begin
12
process ( clk , enable )
begin
i f ( e n a b l e = ’ 1 ’ ) then
i f ( c l k ’ e v e n t and c l k = ’ 1 ’ ) then
memoria ( e n d e r e c o ) <= dados ;
end i f ;
end i f ;
end p r o c e s s ;
s <= memoria ( e n d e r e c o ) ;
end a r c h i t e c t u r e ;
13
8 Código em VHDL - Módulo Banco de Re-
gistradores 16 Bits
LIBRARY i e e e ;
USE i e e e . s t d l o g i c 1 1 6 4 . a l l ;
ENTITY B a n c o R e g i s t r a d o r IS
PORT (
clk : in s t d l o g i c ;
rd , reg2 , r e g 1 : i n s t d l o g i c v e c t o r ( 3 downto 0 ) ;
escrita : i n s t d l o g i c v e c t o r ( 1 5 downto 0 ) ;
S a i d a r e g 2 , S a i d a r e g 1 : out s t d l o g i c v e c t o r ( 1 5 downto 0 ) ) ;
END B a n c o R e g i s t r a d o r ;
ARCHITECTURE r e g i s t r a d o r OF B a n c o R e g i s t r a d o r IS
s i g n a l e n a b l e : s t d l o g i c v e c t o r ( 1 5 downto 0 ) ;
s i g n a l sreg0 , sreg1 , sreg2 , sreg3 , sreg4 , sreg5 , sreg6 ,
sreg7 , sreg8 , sreg9 , sreg10 , sreg11 ,
sreg12 , sreg13 , sreg14 , sreg15 :
s t d l o g i c v e c t o r ( 1 5 downto 0 ) ;
component R e g i s t r a d o r 1 6 x 1 6 IS
PORT (
c l k : IN s t d l o g i c ;
reg0 , reg1 , reg2 , reg3 , reg4 , reg5 , reg6 , reg7 , reg8 ,
reg9 , reg10 , reg11 , reg12 , reg13 , reg14 , reg15 , e n a b l e : IN
s t d l o g i c v e c t o r ( 1 5 downto 0 ) ;
sreg0 , sreg1 , sreg2 , sreg3 , sreg4 , sreg5 , sreg6 , sreg7 ,
s r e g 8 , s r e g 9 , s r e g 1 0 , s r e g 1 1 , s r e g 1 2 , s r e g 1 3 , s r e g 1 4 , s r e g 1 5 : OUT s t d
END component ;
component D e c o d i f i c a d o r i s
port (
e n d e r e c o : i n s t d l o g i c v e c t o r ( 3 downto 0 ) ;
s : out s t d l o g i c v e c t o r ( 1 5 downto 0 ) ) ;
end component ;
component Mux16X1 IS
14
PORT ( s e l : i n s t d l o g i c v e c t o r ( 3 downto 0 ) ;
reg0 , reg1 , reg2 , reg3 , reg4 , reg5 , reg6 , reg7 , reg8 ,
reg9 , reg10 , reg11 , reg12 , reg13 , reg14 , r e g 1 5 : IN
STD LOGIC vector ( 15 downto 0 ) ;
s : OUT STD LOGIC vector (1 5 downto 0 ) ) ;
END component ;
BEGIN
decodificador
dec0 : D e c o d i f i c a d o r p o r t map ( rd , e n a b l e ) ;
r e g 0 : R e g i s t r a d o r 1 6 X 1 6 p o r t map ( c l k , e s c r i t a , e s c r i t a ,
escrita , escrita , escrita , escrita , escrita , escrita ,
escrita , escrita , escrita , escrita , escrita , escrita ,
e s c r i t a , e s c r i t a , e s c r i t a , e s c r i t a , e s c r i t a , e na bl e ,
sreg0 , sreg1 , sreg2 , sreg3 , sreg4 , sreg5 , sreg6 , sreg7 ,
sreg8 , sreg9 , sreg10 , sreg11 , sreg12 , sreg13 , sreg14 ,
sreg15 ) ;
end a r c h i t e c t u r e ;
15
Figura 10: Exemplo Simulação Registrador 16X16
16
9 Código em VHDL - Módulo BrenKung16Bits
LIBRARY i e e e ;
USE i e e e . s t d l o g i c 1 1 6 4 . a l l ;
Gg ( 0 ) <= g ( 1 ) o r ( g ( 0 ) and p ( 1 ) ) ;
Pp ( 0 ) <= p ( 1 ) and p ( 0 ) ;
Gg ( 1 ) <= g ( 3 ) o r ( g ( 2 ) and p ( 3 ) ) ;
Pp ( 1 ) <= p ( 3 ) and p ( 2 ) ;
Gg ( 2 ) <= g ( 5 ) o r ( g ( 4 ) and p ( 5 ) ) ;
Pp ( 2 ) <= p ( 5 ) and p ( 4 ) ;
Gg ( 3 ) <= g ( 7 ) o r ( g ( 6 ) and p ( 7 ) ) ;
Pp ( 3 ) <= p ( 7 ) and p ( 6 ) ;
Gg ( 4 ) <= g ( 9 ) o r ( g ( 8 ) and p ( 9 ) ) ;
Pp ( 4 ) <= p ( 9 ) and p ( 8 ) ;
Gg ( 5 ) <= g ( 1 1 ) o r ( g ( 1 0 ) and p ( 1 1 ) ) ;
Pp ( 5 ) <= p ( 1 1 ) and p ( 1 0 ) ;
Gg ( 6 ) <= g ( 1 3 ) o r ( g ( 1 2 ) and p ( 1 3 ) ) ;
Pp ( 6 ) <= p ( 1 3 ) and p ( 1 2 ) ;
Gg ( 7 ) <= g ( 1 5 ) o r ( g ( 1 4 ) and p ( 1 5 ) ) ;
Pp ( 7 ) <= p ( 1 5 ) and p ( 1 4 ) ;
17
Gg ( 8 ) <= Gg( 1 ) o r (Gg( 0 ) and Pp ( 1 ) ) ;
Pp ( 8 ) <= Pp ( 1 ) and Pp ( 0 ) ;
s (0)<= p(0);
s (1)<= p ( 1 ) xor g ( 0 ) ;
s (2)<= p ( 2 ) xor c ( 1 ) ;
s (3)<= p ( 3 ) xor c ( 2 ) ;
s (4)<= p ( 4 ) xor c ( 3 ) ;
s (5)<= p ( 5 ) xor c ( 4 ) ;
s (6)<= p ( 6 ) xor c ( 5 ) ;
s (7)<= p ( 7 ) xor c ( 6 ) ;
s (8)<= p ( 8 ) xor c ( 7 ) ;
s (9)<= p ( 9 ) xor c ( 8 ) ;
s (10)<= p ( 1 0 ) xor c ( 9 ) ;
s (11)<= p ( 1 1 ) xor c ( 1 0 ) ;
s (12)<= p ( 1 2 ) xor c ( 1 1 ) ;
s (13)<= p ( 1 3 ) xor c ( 1 2 ) ;
s (14)<= p ( 1 4 ) xor c ( 1 3 ) ;
s (15)<= p ( 1 5 ) xor c ( 1 4 ) ;
18
cout<= c ( 1 5 ) ;
end a r c h i t e c t u r e ;
19
10 Código em VHDL - Módulo ULA
LIBRARY i e e e ;
USE i e e e . s t d l o g i c 1 1 6 4 . a l l ;
ENTITY ULA IS
PORT (
a, b, slt : IN STD LOGIC vector (1 5 downto 0 ) ;
z e r o : out STD LOGIc ;
s: OUT STD LOGIC vector ( 1 5 downto 0 ) ;
inverteBit : IN STD LOGIC ;
Operacao : IN STD LOGIC vector ( 1 downto 0 ) ;
CarryOut : out STD LOGIc ) ;
END ULA;
component Mux2X1 i s p o r t (
s e l : in s t d l o g i c ;
b : IN STD LOGIC vector ( 15 downto 0 ) ;
s : OUT STD LOGIC vector (1 5 downto 0 ) ) ;
end component ;
component Mux4X1 i s p o r t (
s e l : in s t d l o g i c v e c t o r ( 1 downto 0 ) ;
s i n 1 , s i n 2 , s i n 3 , s l t : IN STD LOGIC vector (1 5 downto 0 ) ;
s : OUT STD LOGIC vector (1 5 downto 0 ) ) ;
end component ;
component BrenKung16Bits i s p o r t (
a , b : IN STD LOGIC VECTOR (1 5 DOWNTO 0 ) ;
s: OUT STD LOGIC VECTOR (1 5 DOWNTO 0 ) ;
c o u t : out STD LOGIC ) ;
end component ;
begin
20
S i n 1 <= a and s i n 4 ;
S i n 2 <= a o r s i n 4 ;
process ( sin3 )
begin
i f ( s i n 3 = ”00000000000000000000000000000000”) then
z e r o <= ’ 1 ’ ;
else
z e r o <= ’ 0 ’ ;
end i f ;
end p r o c e s s ;
end a r c h i t e c t u r e ;
21
11 Código em VHDL - Módulo Pipeline
LIBRARY i e e e ;
USE i e e e . s t d l o g i c 1 1 6 4 . a l l ;
ENTITY P i p e l i n e IS
PORT (
clk : IN s t d l o g i c ;
reg1 , r e g 2 : IN s t d l o g i c v e c t o r ( 1 5 downto 0 ) ;
Sreg1 , Sreg2 : OUT s t d l o g i c v e c t o r ( 1 5 downto 0 )
);
END P i p e l i n e ;
ARCHITECTURE p i p e l i n e OF P i p e l i n e IS
BEGIN
PROCESS( c l k )
BEGIN
IF ( c l k ’EVENT AND c l k = ’ 1 ’ ) THEN
Sreg1 <= r e g 1 ;
Sreg2 <= r e g 2 ;
END IF ;
END PROCESS;
END a r c h i t e c t u r e ;
22
Figura 14: Exemplo Simulação Pipeline
LIBRARY i e e e ;
USE i e e e . s t d l o g i c 1 1 6 4 . a l l ;
us e IEEE . s t d l o g i c u n s i g n e d . a l l ;
USE i e e e . s t d l o g i c a r i t h . ALL ;
23
component P i p e l i n e IS
PORT (
c l k : IN s t d l o g i c ;
reg1 , r e g 2 : IN s t d l o g i c v e c t o r ( 1 5 downto 0 ) ;
Sreg1 , Sreg2 : OUT s t d l o g i c v e c t o r ( 1 5 downto 0 ) ) ;
END component ;
component ULA IS
PORT (
a , b , s l t : IN STD LOGIC vector (1 5 downto 0 ) ;
z e r o : out STD LOGIc ;
s : OUT STD LOGIC vector (1 5 downto 0 ) ;
i n v e r t e B i t : IN STD LOGIC ;
Operacao : IN STD LOGIC vector ( 1 downto 0 ) ;
CarryOut : out STD LOGIc
);
END component ;
component ram i s
port (
e n a bl e , c l k : i n s t d l o g i c ;
e n d e r e c o : i n i n t e g e r range 0 t o 1 5 ;
dados : i n s t d l o g i c v e c t o r ( 1 5 downto 0 ) ;
s : out s t d l o g i c v e c t o r ( 1 5 downto 0 ) ) ;
end component ;
component Mux21com16bits i s
port (
s e l : in s t d l o g i c ;
a , b : IN STD LOGIC vector (1 5 downto 0 ) ;
y : OUT STD LOGIC vector (1 5 downto 0 ) ) ;
end component ;
s i g n a l e s c r e v e , p1 , p2 : s t d l o g i c v e c t o r (1 6 downto 0 ) ;
s i g n a l c : i n t e g e r range 0 t o 1 5 ;
begin
24
p i p e : P i p e l i n e p o r t map ( c l k , s r e g 1 , s r e g 2 , p1 , p2 ) ;
c <= ( c o n v i n t e g e r ( u n s i g n e d ( saidaULA ) ) ) ;
memram : ram p o r t map ( en ab l e , c l k , c , p2 , saidaram ) ;
25
13 Conclusão
Neste trabalho abordámos o desenvolvimento de uma estrutura de escrita
e leitura na memória de dados dos do processador Mips com barramento de
16 Bits e concluı́mos com exito o desenvolvimento de cada código com sua
respectiva simulação.
Cumprimos todos os objetivos que nos tı́nhamos proposto, uma vez que se
tinha o conhecimento básico para o desenvolvimento e o apoio de nosso Pro-
fessor quando solicitado.
Este trabalho foi de suma importância para o meu aprofundamento deste
tema, pois me permitiu conhecer melhor a linguagem de programação VHDL
em alto nı́vel, instigando o meu conhecimento além do necessário.
26
Bibliografia
PROFA. LUIZA M. R. CODÁ. Apostila de Introdução a VHDL. São Paulo. 2014.
27