-
Notifications
You must be signed in to change notification settings - Fork 0
/
Comp.vhd
73 lines (63 loc) · 1.83 KB
/
Comp.vhd
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
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE work.cpu_lib.ALL;
ENTITY Comp IS
PORT (
a, b : IN bit16;
sel : IN t_comp;
compout : OUT STD_LOGIC
);
END Comp;
ARCHITECTURE CompArch OF Comp IS
BEGIN
-- The comparator consists of a large case statement where each branch of the case statement contains an IF.
-- If the condition tested is true, a '1' value is assigned; otherwise, a '0' is assigned.
PROCESS
BEGIN
CASE sel IS
-- Is (a) Equal (b) ?
WHEN eq =>
IF a = b THEN
compout <= '1';
ELSE
compout <= '0';
END IF;
-- Is (a) Not Equal (b) ?
WHEN neq =>
IF a /= b THEN
compout <= '1';
ELSE
compout <= '0';
END IF;
-- Is (a) Greater Than (b) ?
WHEN gt =>
IF a > b THEN
compout <= '1';
ELSE
compout <= '0';
END IF;
-- Is (a) Greater Than or Equal (b) ?
WHEN gte =>
IF a >= b THEN
compout <= '1';
ELSE
compout <= '0';
END IF;
-- Is (a) Less Than (b) ?
WHEN lt =>
IF a < b THEN
compout <= '1';
ELSE
compout <= '0';
END IF;
-- Is (a) Less Than or Equal (b) ?
WHEN lte =>
IF a <= b THEN
compout <= '1';
ELSE
compout <= '0';
END IF;
WHEN OTHERS => compout <= '0';
END CASE;
END PROCESS;
END CompArch;