Subversion Repositories programming

Rev

Rev 195 | Rev 197 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
195 ira 1
module ALU4 (a, b, cin, op, cout, result);
2
    input[0:3] a, b;
3
    input[0:1] op;
4
    input cin;
5
 
6
    output[0:3] result;
7
    output cout;
8
 
9
    wire bit3_cout, bit2_cout, bit1_cout;
10
 
196 ira 11
    /* Link 4 1-bit ALU's together to make a 4-bit ALU.
12
     * Connect from LSB to MSB so the ripple-carry works correctly. */
195 ira 13
    ALU1 bit3 (a[3], b[3], cin, op, bit3_cout, result[3]);
14
    ALU1 bit2 (a[2], b[2], bit3_cout, op, bit2_cout, result[2]);
15
    ALU1 bit1 (a[1], b[1], bit2_cout, op, bit1_cout, result[1]);
16
    ALU1 bit0 (a[0], b[0], bit1_cout, op, cout, result[0]);
17
endmodule
18
 
19
module test_ALU4;
20
    reg[0:3] x;
21
    reg[0:3] y;
22
    reg[0:1] op;
23
    reg cin;
24
 
25
    wire[0:3] result;
26
    wire cout;
27
 
28
    initial begin
29
        $monitor ("time=%0d a=%b b=%b op=%b cin=%b cout=%b result=%b",
30
                $time, x, y, op, cin, cout, result);
31
    end
32
 
33
    initial begin
34
 
196 ira 35
           x='b0101; y='b1011; op='b00; cin=0;
36
        #1 x='b0101; y='b1011; op='b01; cin=0;
37
        #1 x='b0101; y='b1011; op='b10; cin=0;
38
        #1 x='b1101; y='b0011; op='b00; cin=0;
39
        #1 x='b1010; y='b0011; op='b01; cin=0;
40
        #1 x='b0101; y='b0011; op='b10; cin=0;
41
        #1 x='b1010; y='b1001; op='b10; cin=0;
195 ira 42
 
43
    end
44
 
45
    ALU4 alu4 (x, y, cin, op, cout, result);
46
 
47
endmodule