1. 1-bit Full Adder

- gate-level diagram

 

- Verilog code

module

module full_adder_1bit_SM(sum, c_out, x, y, c_in);

input x, y, c_in;

output sum, c_out;

wire s1, c1, c2;

xor xor1 (s1, x, y);

and and1 (c1, x, y);

xor xor2 (sum, c_in, s1);

and and2 (c2, c_in, s1);

or or3 (c_out, c1, c2);

endmodule

testbench

module tb;

    reg x, y, c_in;

    wire sum, c_out;

    

    full_adder_1bit_SM uut (sum, c_out, x, y, c_in);

    

    initial begin

    x = 0; y = 0; c_in = 0;

    

    end

    

    always #80 x <= ~x;

    always #40 y <= ~y;

    always #20 c_in <= ~c_in;

    

endmodule

- Output

 

2. 4-to-1 MUX

- gate-level diagram

 

- Verilog code

module 

module mux4_to_1_SM (i0, i1, i2, i3, s1, s0, out);

    input i0, i1, i2, i3, s1, s0;

    output out;

    wire s1n, s0n;

    wire i0o, i1o, i2o, i3o;

    not not1 (s0n, s0);

    not not2 (s1n, s1);

    and and1 (i0o, i0, s1n, s0n);

    and and2 (i1o, i1, s1n, s0);

    and and3 (i2o, i2, s1, s0n);

    and and4 (i3o, i3, s1, s0);

    or or1 (out, i0o, i1o, i2o, i3o);

endmodule

Testbench

module tb; 

    reg i0, i1, i2, i3, s1, s0; 
    wire out; 
     
    mux4_to_1_SM uut (i0, i1, i2, i3, s1, s0, out); 
     
    initial begin 
    i0 = 0; i1 = 0; i2 = 0; i3 = 0; s1 = 0; s0 = 0; 
     
    #20 i0 = 1; i1 = 0; i2 = 0; i3 = 0; s1 = 0; s0 = 0; 
    #20 i0 = 0; i1 = 1; i2 = 0; i3 = 0; s1 = 0; s0 = 1; 
    #20 i0 = 0; i1 = 0; i2 = 1; i3 = 0; s1 = 1; s0 = 0; 
    #20 i0 = 0; i1 = 0; i2 = 0; i3 = 1; s1 = 1; s0 = 1;  
     
    end 
endmodule

 

- Output

 

3. 2-to-4 Decoder

- gate-level diagram

 

- Verilog code

module

module decoder_2_to_4_SM(D0, D1, D2, D3, EN, A1, A0);

input EN, A1, A0;

output D0, D1, D2, D3;

wire A1n, A0n, N0, N1, N2, N3;

not not1 (A1n, A1),

    not2 (A0n, A0);

and and1 (N0, A1n, A0n),

    and2 (N1, A1n, A0),

    and3 (N2, A1, A0n),

    and4 (N3, A1, A0);

    

and and5 (D0, N0, EN),

    and6 (D1, N1, EN),

    and7 (D2, N2, EN),

    and8 (D3, N3, EN);

    

endmodule

 

- Output

truth table과 동일하게 작동하는 것을 확인할 수 있다.

'전자공학 > Verilog' 카테고리의 다른 글

Hierarchical Design of 4-bit Adder  (0) 2020.07.20
Testbench를 기술하는 방법  (0) 2020.07.20
Structural Modeling  (0) 2020.07.17

+ Recent posts