-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMCD.vhdl
89 lines (85 loc) · 3.9 KB
/
MCD.vhdl
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
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity MaximoComunDivisor is
generic(
n : integer := 8
);
port(
reloj : in std_logic;
reset : in std_logic;
pulsoa : in std_logic;
pulsob : in std_logic;
dato : in std_logic_vector( n-1 downto 0 );
fin : out std_logic;
salida : out std_logic_vector( n-1 downto 0 )
);
end MaximoComunDivisor;
architecture arch of MaximoComunDivisor is
signal a: std_logic_vector( n-1 downto 0 );
signal b: std_logic_vector( n-1 downto 0 );
signal r: std_logic_vector( n-1 downto 0 );
type states is ( ereset, e1, e2, eamayor, ebmayor, e3, e4, efin );
signal state: states;
begin
mcd: process( reloj, reset )
begin
if reset = '1' then
state <= ereset;
elsif reloj'event and reloj = '1' then
case state is
when ereset =>
fin <= '0';
if pulsoa = '0' then
state <= e1;
end if;
when e1 =>
fin <= '0';
a <= dato;
salida <= dato;
if pulsob = '0' then
state <= e2;
end if;
when e2 =>
b <= dato;
salida <= dato;
if a > b then
state <= eamayor;
elsif a < b then
state <= ebmayor;
state <= efin;
end if;
when eamayor =>
r <= std_logic_vector( unsigned( a ) - unsigned( b ) );
state <= e3;
when ebmayor =>
r <= std_logic_vector( unsigned( b ) - unsigned( a ) );
if r > b then
state <= eamayor;
elsif r < b then
state <= ebmayor;
else
state <= efin;
end if;
when e4 =>
b <= r;
if r > a then
state <= ebmayor;
elsif r < a then
state <= eamayor;
else
state <= efin;
end if;
when efin =>
salida <= a;
fin <= '1';
if pulsoa = '0' then
state <= e1;
else
state <= efin;
end if;
end case;
end if;
end process;
);
end arch;