-
Notifications
You must be signed in to change notification settings - Fork 0
/
Basic_gates.v
73 lines (71 loc) · 2.98 KB
/
Basic_gates.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
//AND Gate using dataflow modelling
module AND_Gate(
input a,b, //Input declaration
output out); //Output declaration
assign out = a & b;
endmodule
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
//OR Gate uaing datadlow modelling
module OR_Gate(
input a,b, //Input declaration
output out); //Output declaration
assign out = a|b;
endmodule
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
//NOT Gate using dataflow modelling
module NOT_Gate(
input in, //Input declaration
output out); //Output declaration
assign out = ~in;
endmodule
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
//NAND Gate using dataflow modelling
module NAND_Gate(
input a,b, //Input declaration
output out); //Output declaration
assign out = ~(a&b);
endmodule
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
//NAND Gate using "INSTANTIATION"......Structural modelling
module NAND_Gate(
input a,b,
output out);
wire w1;
AND_Gate inst1(a,b,w1);
NOT_Gate inst2(w1,out);
endmodule
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
//NOR Gate using dataflow modelling
module NOR_Gate(
input a,b, //Input declaration
output out); //Output declaration
assign out = ~(a|b);
endmodule
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
//NOR Gate using "INSTANTIATION"........Sturctural modelling
module NOR_Gate(
input a,b, //Input declaration
output out); //Output declaration
wire w1;
OR_Gate inst1(a,b,w1);
NOT_Gate inst2(w1,out);
endmodule
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
//XOR Gate using dataflow modelling
module XOR_Gate(
input a,b,
output out);
assign out = (a&(~b)) | ((~a)&b);
endmodule
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
//XOR Gate using "INSTANTIATION"..............Structural modelling
module XOR_Gate(
input a,b,
output out);
wire w1,w2,w3;
NAND_Gate inst1(a,b,w1);
AND_Gate inst2(a,w1,w2);
AND_Gate inst2(a,w1,w3);
OR_Gate inst3(w2,w3,out);
endmodule
----------------------------------------------------------------------------------------------------------------------------------------------------------------------