Thursday, June 8, 2017

VERILOG PROGRAM FOR RIPPLE CARRY ADDER



RIPPLE CARRY ADDER
module RCA4(cout,s,cin,a,b);
input[3:0]a,b;
input cin;
output[3:0]s;
output cout;
wire c1,c2,c3,c4;
full_adder a1(c1,s[0],a[0],b[0],cin);
full_adder a2(c2,s[1],a[1],b[1],c2);
full_adder a3(c3,s[2],a[2],b[2],c3);
full_adder a4(c4,s[3],a[3],b[3],cout);
endmodule;

VERILOG PROGRAM FOR DECADE COUTER



DECADE-COUNTER
module decade_counter(q,reset,clk);
input clk,reset;
output reg [3:0]q;
wire a;
assign a=q[1]&&q[3];
always@(posedge reset or negedge clk or posedge a)
begin
if(reset||a)
q<=4'b0;
else
q<=q+1;
end
endmodule

VERILOG PROGRAM FOR D FLIP FLOP



D-FLIP FLOP
module dff(d,clk,rst,q,qb);
input d,clk,rst;
output q,qb;
reg q,qb;
reg temp=0;
always@(posedge clk,posedge rst)
begin
if(rst==0)
temp=d;
else
temp=temp;
q=temp;
qb=~temp;
end
endmodule

VERILOG PROGRAM FOR SR FLIP FLOP





SR-FLIPFLOP
module srff(q,q1,r,s,clk);
output q,q1;
input r,s,clk;
reg q,q1;
initial
begin
q=1'b0;
q1=1'b1;
end
always@(posedge clk)
begin
case({s,r})
{1'b0,1'b0}:begin q=q;q1=q1;end
{1'b0,1'b1}:begin q=1'b0;q1=1'b1;end
{1'b1,1'b0}:begin q=1'b1;q1=1'b0;end
{1'b1,1'b1}:begin q=1'b1;q1=1'b1;end
endcase
end
endmodule

VERILOG PROGRAM FOR 2 BIT COMPARATOR



2BIT_COPARATOR
module comparator_2bit(a,b,equal,greater,lower);
output equal,greater,lower;
input [1:0]a,b;
assign equal=(a==b)?1:0;
assign greater=(a>b)?1:0;
assign lower=(a<b)?1:0;
endmodule