Subversion Repositories programming

Rev

Rev 195 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 195 Rev 207
Line 1... Line 1...
1
 
1
 
2
//Basic unit: 2-input and gate
2
//Basic unit: 2-input and gate
3
module AND_2 (in1, in2, out);
3
module AND_2 (in1, in2, out);
4
   input in1, in2;
4
   input in1, in2;
5
   output out;                  
5
   output out;
6
   assign out = in1 & in2;
6
   assign out = in1 & in2;
7
endmodule
7
endmodule
8
 
8
 
9
//Basic unit: 2-input or gate
9
//Basic unit: 2-input or gate
10
module OR_2 (in1, in2, out);
10
module OR_2 (in1, in2, out);
Line 21... Line 21...
21
endmodule
21
endmodule
22
 
22
 
23
//Basic unit: 3-input and gate
23
//Basic unit: 3-input and gate
24
module AND_3 (in1, in2, in3, out);
24
module AND_3 (in1, in2, in3, out);
25
   input in1, in2, in3;
25
   input in1, in2, in3;
26
   output out;                  
26
   output out;
27
   assign out = in1 & in2 & in3;
27
   assign out = in1 & in2 & in3;
28
endmodule
28
endmodule
29
 
29
 
30
//Basic unit: 4-input or gate
30
//Basic unit: 4-input or gate
31
module OR_4 (in1, in2, in3, in4, out);
31
module OR_4 (in1, in2, in3, in4, out);
Line 46... Line 46...
46
   input a, b, op;
46
   input a, b, op;
47
   output out;
47
   output out;
48
   wire w1, w2, w3;
48
   wire w1, w2, w3;
49
 
49
 
50
   NOT_1 not1 (op, w1);
50
   NOT_1 not1 (op, w1);
51
   
51
 
52
   AND_2 and2 (a, w1, w2);
52
   AND_2 and2 (a, w1, w2);
53
   AND_2 and1 (b, op, w3);
53
   AND_2 and1 (b, op, w3);
54
 
54
 
55
   OR_2 or1 (w2, w3, out);
55
   OR_2 or1 (w2, w3, out);
56
endmodule
56
endmodule
57
 
57
 
58
//basic unit: 3-input NAND gate
58
//basic unit: 3-input NAND gate
59
module NAND_3 (in1, in2, in3, out);
59
module NAND_3 (in1, in2, in3, out);
60
  input in1, in2, in3;
60
  input in1, in2, in3;
61
  output out;    
61
  output out;
62
  assign out = ~(in1 & in2 & in3);
62
  assign out = ~(in1 & in2 & in3);
63
endmodule
63
endmodule
64
 
64
 
65
//basic unit: 4-input NAND gate
65
//basic unit: 4-input NAND gate
66
module NAND_4 (in1, in2, in3, in4, out);
66
module NAND_4 (in1, in2, in3, in4, out);
Line 70... Line 70...
70
endmodule
70
endmodule
71
 
71
 
72
// basic unit: 2-input NAND gate
72
// basic unit: 2-input NAND gate
73
module NAND_2 (in1, in2, out);
73
module NAND_2 (in1, in2, out);
74
   input in1, in2;
74
   input in1, in2;
75
   output out;     
75
   output out;
76
   assign out = ~(in1 & in2);
76
   assign out = ~(in1 & in2);
77
endmodule
77
endmodule
78
 
78
 
79
// basic unit: 2-input NOR gate
79
// basic unit: 2-input NOR gate
80
module NOR_2 ( in1, in2, out);
80
module NOR_2 ( in1, in2, out);
Line 89... Line 89...
89
   input [0:1]op;
89
   input [0:1]op;
90
   output out;
90
   output out;
91
   wire w1, w2, f1, f2, f3, f4;
91
   wire w1, w2, f1, f2, f3, f4;
92
 
92
 
93
   //instantiate two NOT gates
93
   //instantiate two NOT gates
94
   NOT_1 not1 (op[0:0], w1); 
94
   NOT_1 not1 (op[0:0], w1);
95
   NOT_1 not2 (op[1:1], w2);
95
   NOT_1 not2 (op[1:1], w2);
96
 
96
 
97
   //instantiate four 3-input NAND gates
97
   //instantiate four 3-input NAND gates
98
   NAND_3 nand3_1 (a, w1, w2, f1);
98
   NAND_3 nand3_1 (a, w1, w2, f1);
99
   NAND_3 nand3_2 (b, w1, op[1:1], f2);
99
   NAND_3 nand3_2 (b, w1, op[1:1], f2);
Line 145... Line 145...
145
 
145
 
146
   Sum sum_gate (carryIn, a, b, sum);
146
   Sum sum_gate (carryIn, a, b, sum);
147
   CarryOut cout (carryIn, a, b, carryOut);
147
   CarryOut cout (carryIn, a, b, carryOut);
148
endmodule
148
endmodule
149
 
149
 
150
 
150
 
151
// module for the 1-bit ALU
151
// module for the 1-bit ALU
152
module ALU1 (a, b, binvert, carryIn, op, carryOut, result);
152
module ALU1 (a, b, binvert, carryIn, op, carryOut, result);
153
   input a, b, binvert, carryIn;
153
   input a, b, binvert, carryIn;
154
   input [0:1]op;
154
   input [0:1]op;
155
   output carryOut, result;
155
   output carryOut, result;
Line 165... Line 165...
165
   OneBitAdder adder (carryIn, a, w2, carryOut, w5);
165
   OneBitAdder adder (carryIn, a, w2, carryOut, w5);
166
 
166
 
167
   Mux4 mux4 (w3, w4, w5, dead, op, result);
167
   Mux4 mux4 (w3, w4, w5, dead, op, result);
168
endmodule
168
endmodule
169
 
169
 
170
/*
-
 
171
module test_alu1;
170
module test_alu1;
172
 
171
 
173
    reg a, b, cin, binvert;
172
    reg a, b, cin, binvert;
174
    reg[0:1] op;
173
    reg[0:1] op;
175
    wire cout, result;
174
    wire cout, result;
Line 220... Line 219...
220
        #1 a=1; b=1; cin=0; op='b10;
219
        #1 a=1; b=1; cin=0; op='b10;
221
        #1 a=1; b=1; cin=1; op='b10;
220
        #1 a=1; b=1; cin=1; op='b10;
222
    end
221
    end
223
 
222
 
224
endmodule
223
endmodule
225
*/
-
 
226
 
224