Subversion Repositories programming

Rev

Rev 194 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 194 Rev 195
Line 141... Line 141...
141
//module a 1-bit adder
141
//module a 1-bit adder
142
module OneBitAdder (carryIn, a, b, carryOut, sum);
142
module OneBitAdder (carryIn, a, b, carryOut, sum);
143
   input carryIn, a, b;
143
   input carryIn, a, b;
144
   output carryOut, sum;
144
   output carryOut, sum;
145
 
145
 
146
   Sum sum (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
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
//Test bench for 1-bit ALU 
-
 
171
module ALU1test;     
-
 
172
        reg a, b, binv, cin;
-
 
173
        reg [0:1]op;
-
 
174
        wire cout, result;		
-
 
175
       
-
 
176
initial begin
-
 
177
    a=0; b=0;binv=0;op=00;cin=0;
-
 
178
    #1 a=0; b=1;
-
 
179
    #1 a=1; b=0;
-
 
180
    #1 a=1; b=1;
-
 
181
    #1 a=0; b=0; op=01;
-
 
182
    #1 a=0; b=1; 
-
 
183
    #1 a=1; b=0;
-
 
184
    #1 a=1; b=1;
-
 
185
    #1 a=0; b=0; op=10;
-
 
186
    #1 a=0; b=1; 
-
 
187
    #1 a=1; b=0; 
-
 
188
    #1 a=1; b=1;  
-
 
189
    #1 a=0; b=0; cin=1;
-
 
190
    #1 a=0; b=1;
-
 
191
    #1 a=1; b=0;
-
 
192
    #1 a=1; b=1;
-
 
193
end
-
 
194
 
170
/*
195
initial begin
171
module test_alu1;
196
   $display( "time     A     B    op     cin   cout result  ");
-
 
197
   $monitor("time=%0d a=%b  b=%b  op=%b  cin=%b  cout=%b, result=%b", 
-
 
198
              $time, a, b, op, cin, cout, result);	
-
 
199
end
-
 
200
 
172
 
-
 
173
    reg a, b, cin, binvert;
-
 
174
    reg[0:1] op;
-
 
175
    wire cout, result;
-
 
176
 
201
   ALU1 g1(a,b,binv,cin,op,cout,result);
177
    ALU1 alu1 (a, b, binvert, cin, op, cout, result);
-
 
178
 
-
 
179
    initial begin
-
 
180
        $monitor ("time=%0d a=%b b=%b op=%b cin=%b cout=%b result=%b",
-
 
181
            $time, a, b, op, cin, cout, result);
-
 
182
    end
-
 
183
 
-
 
184
    initial begin
-
 
185
        binvert=0;
-
 
186
           a=0; b=0; cin=0; op=00; $display; $display("AND");
-
 
187
        #1 a=0; b=0; cin=1; op=00;
-
 
188
        #1 a=0; b=1; cin=0; op=00;
-
 
189
        #1 a=0; b=1; cin=1; op=00;
-
 
190
        #1 a=1; b=0; cin=0; op=00;
-
 
191
        #1 a=1; b=0; cin=1; op=00;
-
 
192
        #1 a=1; b=1; cin=0; op=00;
-
 
193
        #1 a=1; b=1; cin=1; op=00;
-
 
194
 
-
 
195
        #1 a=0; b=0; cin=0; op=01; $display; $display ("OR");
-
 
196
        #1 a=0; b=0; cin=1; op=01;
-
 
197
        #1 a=0; b=1; cin=0; op=01;
-
 
198
        #1 a=0; b=1; cin=1; op=01;
-
 
199
        #1 a=1; b=0; cin=0; op=01;
-
 
200
        #1 a=1; b=0; cin=1; op=01;
-
 
201
        #1 a=1; b=1; cin=0; op=01;
-
 
202
        #1 a=1; b=1; cin=1; op=01;
-
 
203
 
-
 
204
        #1 a=0; b=0; cin=0; op='b10; $display; $display ("ADD");
-
 
205
        #1 a=0; b=0; cin=1; op='b10;
-
 
206
        #1 a=0; b=1; cin=0; op='b10;
-
 
207
        #1 a=0; b=1; cin=1; op='b10;
-
 
208
        #1 a=1; b=0; cin=0; op='b10;
-
 
209
        #1 a=1; b=0; cin=1; op='b10;
-
 
210
        #1 a=1; b=1; cin=0; op='b10;
-
 
211
        #1 a=1; b=1; cin=1; op='b10; // <-- BUG HERE
-
 
212
 
-
 
213
        binvert=1;
-
 
214
        #1 a=0; b=0; cin=0; op='b10; $display; $display ("SUB");
-
 
215
        #1 a=0; b=0; cin=1; op='b10;
-
 
216
        #1 a=0; b=1; cin=0; op='b10;
-
 
217
        #1 a=0; b=1; cin=1; op='b10;
-
 
218
        #1 a=1; b=0; cin=0; op='b10;
-
 
219
        #1 a=1; b=0; cin=1; op='b10;
-
 
220
        #1 a=1; b=1; cin=0; op='b10;
-
 
221
        #1 a=1; b=1; cin=1; op='b10;
-
 
222
    end
202
 
223
 
203
endmodule
224
endmodule
-
 
225
*/
-
 
226