Verrilog Programs 1
Verrilog Programs 1
A full adder is a combinational circuit that takes three input a, b, c and generate output as
sum and carry. The full adder adds the three input producing two outputs sum and carry.
Let us say that the three input to the full adder are A,B,C then logical Expression for Sum
will be (A) xor (B) xor (C) . And the logical expression for carry will be AB+BC+AC.
0 0 0 0 0
0 0 1 1 0
0 1 0 1 0
0 1 1 0 1
1 0 0 1 0
1 0 1 0 1
1 1 0 0 1
1 1 1 1 1
Block diagram:
1|P ag e
Verilog code:
case ({a,b,c})
3'b000: cout = 0;
3'b001: cout = 0;
3'b010: cout = 0;
3'b011: cout = 1;
3'b100: cout = 0;
3'b101: cout = 1;
3'b110: cout = 1;
3'b111: cout = 1;
default : cout = 0;
endcase
end
endmodule
2|P ag e
2. Verilog code for Ripple carry adder.
3|P ag e
3. Verilog code for 8:1 Multiplexer
4|P ag e
4. Verilog code for 2 bit magnitude comparator
Behavioural Modeling Structural Modeling Dataflow Modeling
module comp2bit(G,L,E,a,b); module module comparator_2bit ( a ,b ,equal
comparator_2bit_gatelevel(G,E,L,a,b) ,greater ,lower);
input a,b;
output G,L,E; output G,E,L; output equal ;
always @ (a or b) input [1:0]a,b; output greater ;
begin output lower ;
wire a1bar,a0bar,b1bar,b0bar;
if(a>b)
wire input [1:0] a ;
G=1,L=0, E=0; w1,w2,w3,w4,w5,w6,w7,w8,w9,w10; input [1:0] b ;
elseif(a<b) not n1(a1bar,a[1]);
G=0,L=1,E=0; not n2(a0bar,a[0]); assign equal = (a==b) ? 1 : 0;
else not n3(b1bar,b[1]); assign greater = (a>b) ? 1 : 0;
not n4(b0bar,b[0]); assign lower = (a<b) ? 1 : 0;
G=0,L=0,E=1;
endmodule and x1(w1,a[1],b1bar); endmodule
and x2(w2,a[1],a[0],b0bar);
and x3(w3,a[0],b1bar,b0bar);
and x4(w4,a1bar,a0bar,b1bar,b0bar);
and x5(w5,a1bar,a[0],b1bar,b[0]);
and x6(w6,a[1],a0bar,b[1],b0bar);
and x7(w7,a[1],a[0],b[1],b[0]);
and x8(w8,a1bar,b[1]);
and x9(w9,a1bar,a0bar,b[0]);
and x10(w10,a0bar,b[1],b[0]);
or x11(G,w1,w2,w3);
or x12(E,w4,w5,w6,w7);
or x13(L,w8,w9,w10);
endmodule;
5|P ag e