-
Notifications
You must be signed in to change notification settings - Fork 0
/
neander.vhd.bak
108 lines (95 loc) · 3.36 KB
/
neander.vhd.bak
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
LIBRARY IEEE;
USE IEEE.std_logic_1164.ALL;
USE IEEE.std_logic_unsigned.ALL;
USE IEEE.std_logic_arith.ALL;
USE IEEE.std_logic_textio.ALL;
ENTITY neander IS
PORT (
reset : IN STD_LOGIC;
clk : IN STD_LOGIC;
count_load : IN STD_LOGIC;
en_ULA : IN STD_LOGIC;
-- saidas
Z : OUT STD_LOGIC;
N : OUT STD_LOGIC;
decoder : OUT STD_LOGIC_VECTOR(3 DOWNTO 0)
);
END neander;
ARCHITECTURE behavior OF neander IS
-- memoria do neander
TYPE valores IS ARRAY (0 TO 15) OF STD_LOGIC_VECTOR(7 DOWNTO 0);--vetor de 16 posições de 8 bits
-- alterar aqui a memória, infelizmente não consegui implementar com leitura do arquivo
SIGNAL memoria : valores := (0 => "00000001",
1 => "00010001",
2 => "00010011",
3 => "00100110",
4 => "00000000",
5 => "00000000",
6 => "00000000",
7 => "00000000",
8 => "00000000",
9 => "00000000",
10 => "00000000",
11 => "00000000",
12 => "00000000",
13 => "00000000",
14 => "00000000",
15 => "00000000"
);
----------------------------------------------
-- MUX e operações
SIGNAL MUX : STD_LOGIC_VECTOR(7 DOWNTO 0);
SIGNAL SOMA : STD_LOGIC_VECTOR(3 DOWNTO 0);
SIGNAL SUB : STD_LOGIC_VECTOR(3 DOWNTO 0);
SIGNAL MULT : STD_LOGIC_VECTOR(7 DOWNTO 0);
-- registradores
SIGNAL PC : STD_LOGIC_VECTOR(3 DOWNTO 0);
SIGNAL ACC : STD_LOGIC_VECTOR(3 DOWNTO 0);
SIGNAL RDM : STD_LOGIC_VECTOR(7 DOWNTO 0); -- registrador de memoria
SIGNAL flagZ : STD_LOGIC; -- flag se ACC = 0
SIGNAL flagN : STD_LOGIC; -- flag se ACC < 0
----------------------------------------------
BEGIN
-- implementações das operações
SOMA <= RDM(3 DOWNTO 0) + ACC;
SUB <= RDM(3 DOWNTO 0) - ACC;
MULT <= RDM(3 DOWNTO 0) * ACC;
-- mux
-- o uso dos bits 4 e 5 do RDM é para indicar qual operação será feita, conforme visualizado no logisim
MUX <= "0000" & RDM(3 DOWNTO 0) WHEN (RDM(5) = '0' AND RDM(4) = '0') ELSE -- load
"0000" & SOMA(3 DOWNTO 0) WHEN (RDM(5) = '0' AND RDM(4) = '1') ELSE -- soma
"0000" & SUB(3 DOWNTO 0) WHEN (RDM(5) = '1' AND RDM(4) = '0') ELSE -- subtração
"0000" & MULT(7 DOWNTO 4) WHEN (RDM(5) = '1' AND RDM(4) = '1'); -- multiplicaação
-- flags
flagZ <= '1' WHEN (ACC = "0000") ELSE
'0';
flagN <= '1' WHEN (ACC(3) = '1') ELSE
'0';
PROCESS (clk, reset)
BEGIN
-- zera tudo pra não ter problema de lixo
IF reset = '0' THEN
PC <= (OTHERS => '0');
ACC <= (OTHERS => '0');
RDM <= (OTHERS => '0');
count_load <= '0';
en_ULA <= '0';
Z <= '0';
N <= '0';
decoder <= (OTHERS => '0');
ELSIF rising_edge(clk) THEN
IF count_load = '1' THEN
PC <= PC + "0001";
RDM <= memoria(conv_integer(unsigned(PC)));
decoder <= RDM(7 DOWNTO 4); -- os 4 bits mais significativos do RDM são o decoder
ELSE
PC <= RDM(3 DOWNTO 0); -- os 4 bits menos significativos do RDM são o PC
RDM <= memoria(conv_integer(unsigned(PC)));
decoder <= RDM(7 DOWNTO 4);
END IF;
IF en_ULA = '1' THEN
ACC <= MUX(3 DOWNTO 0);
END IF;
END IF;
END PROCESS;
END ARCHITECTURE;