-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathComparison.v
114 lines (98 loc) · 2.15 KB
/
Comparison.v
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
109
110
111
112
113
114
// Connor Humiston
// ECEN2350 Digital Logic
// University of Colorado, Boulder
module Comparison(x, y, SW9, SW8, eqrslt, grrslt, lsrslt, mxout, compare);
input [3:0] x, y;
input SW9, SW8;
output [9:0] eqrslt, grrslt, lsrslt, mxout, compare;
equal eql(x, y, eqrslt);
greaterthan grt(x, y, grrslt);
lessthan less(x, y, lsrslt);
max mx(x, y, mxout);
//for SW9 & SW8
//00 is for equal
//01 is for greater than
//10 is for less than
//11 is for max
Multiplexer op_comp(eqrslt, grrslt, lsrslt, mxout, SW9, SW8, compare);
endmodule
//EQUAL
//outputs 1 if equal and 0 if not equal
module equal(x, y, eqrslt);
input [3:0] x, y;
output reg [3:0] eqrslt;
always @(x, y, eqrslt)
begin
if (x == y)
eqrslt = 1;
else
eqrslt = 0;
end
endmodule
//GREATER
//outputs 1 if x > y and 0 if y >= x
module greaterthan(x, y, grrslt);
input [3:0] x, y;
output reg [3:0] grrslt;
always @(x, y, grrslt)
begin
if (x > y)
grrslt = 1;
else
grrslt = 0;
end
endmodule
//LESS
//outputs 1 if x < y and 0 if y <= x
module lessthan(x, y, lsrslt);
input [3:0] x, y;
output reg [3:0] lsrslt;
always @(x, y, lsrslt)
begin
if (x < y)
lsrslt = 1;
else
lsrslt = 0;
end
endmodule
//MAX
//outputs x if x is maximum and y if y is maximum
module max(x, y, mxout);
input [3:0] x, y;
output reg [3:0] mxout;
always @(mxout)
begin
begin
if (x[3] == 1 & y[3] == 0)
mxout = x;
end
begin
if (y[3] == 1 & x[3] == 0)
mxout = y;
end
begin
if (x[3] == y[3] & x[2] == 1 & y[2] == 0)
mxout = x;
end
begin
if (x[3] == y[3] & x[2] == 0 & y[2] == 1)
mxout = y;
end
begin
if (x[3] == y[3] & x[2] == y[2] & x[1] == 1 & y[1] == 0)
mxout = x;
end
begin
if (x[3] == y[3] & x[2] == y[2] & x[1] == 0 & y[1] == 1)
mxout = y;
end
begin
if (x[3] == y[3] & x[2] == y[2] & x[1] == y[1] & x[0] == 1 & y[0] == 0)
mxout = x;
end
begin
if (x[3] == y[3] & x[2] == y[2] & x[1] == y[1] & x[0] == 0 & y[0]== 1)
mxout = y;
end
end
endmodule