Professional Documents
Culture Documents
Verilog Codes For 4Th Sem Electronic and Communication Students (Vtu)
Verilog Codes For 4Th Sem Electronic and Communication Students (Vtu)
APR
VERILOG CODES FOR 4TH SEM ELECTRONIC AND
19 COMMUNICATION STUDENTS (VTU)
HERE U WILL FIND ALL THE VERILOG CODES NECESSARY FOR YOUR SYLLABUS
//EXPT 2B. VERILOG CODE FOR FULL ADDER USING STRUCYURAL MODULING.
// component ha(half adder).
module ha(a,b, s,c);
input a,b;
output s,c;
assign s=a^b;
assign c=a&b;
endmodule
// full adder using two half adders and or gate
module full_adder_structural(a,b,cin, sum,cout);
input a,b,cin;
output sum,cout;
wire c1,c2,s1;
ha u1(a,b,s1,c1);
ha u2(s1,cin,sum,c2);
or (cout,c1,c2);
endmodule
//EXPT 2C. VERILOG CODE FOR FULL ADDER (DATA FLOW MODEL).
module full_adder_data_flow(a,b,cin, sum,cout);
input a,b,cin;
output sum,cout;
assign sum=a ^ b ^ cin;
assign cout=( a & b ) | ( b & cin ) | ( cin & a );
endmodule
//EXPT NO 2D. VERILOG CODE FOR THE FULL-ADDER(BEHAVIORAL MODEL).
module full_adder_behavioral(a,b,cin,sum,cout);
input a,b,cin;
output reg sum,cout;// o/p are to be declared as registers
reg T1,T2,T3,S1;// as variables in VHDL
always@(a,b,cin)
begin
T1=a&b;
T2=b&cin;
T3=cin&a;
Cout=T1 | T2 | T3;
S1=a^b;
sum=S1^cin;
end
endmodule
// EXPT 2E. VERILOG CODE FOR FULL-ADDER (MIXED STYLE OF MODEL).
module full_adder_mixed(a,b,cin, sum,cout);
input a,b,cin;
output sum, cout;
reg cout;
wire s1;// as signal in vhdl
reg t1,t2,t3;// as variables in vhdl
xor u1(s1,a,b);// structural xor gate
assign sum=s1 ^ cin;// data flow
// carry using behavioral description
always@(a,b,cin)
begin
t1=a & b;
t2=a & cin;
t3=cin & b;
cout=t1 | t2 | t3;
end
endmodule
4 View comments