Verilog Manual
Verilog Manual
module allgate(a,b,y);
input a,b;
output [1:6] y;
assign y[1]= a & b,
y[2]= a | b,
y[3]= ~a ,
y[4]= ~(a & b),
y[5]= ~(a | b),
y[6]= a ^ b;
endmodule
module b2g(b,g);
input [3:0] b;
output [3:0] g;
xor (g[0],b[0],b[1]),
(g[1],b[1],b[2]),
(g[2],b[2],b[3]);
assign g[3]=b[3];
endmodule
module cnt4(rst,clk,q);
input rst,clk;
output [3:0] q;
reg[3:0]q;
always @ (posedge clk)
if (rst==0)
q<= 0;
else
q<=q+1;
endmodule
module comp(a,b,aeqb,agtb,altb);
input [3:0] a,b;
output aeqb,agtb,altb;
reg aeqb,agtb,altb;
always @(a or b)
begin
aeqb=0; agtb=0; altb=0;
if(a==b)
aeqb=1;
else if (a>b)
agtb=1;
else
altb=1;
end
endmodule
module count4(clk,resetn,en,q);
input clk,resetn,en;
output q;
reg q;
module dff(d,clk,q);
input d,clk;
inout q;
reg q;
always@(I or sel)
begin
if(sel==3'b000)
f[7]=I;
else if(sel==3'b001)
f[6]=I;
else if (sel==3'b010)
f[5]=I;
else if (sel==3'b011)
f[4]=I;
else if (sel==3'b100)
f[3]=I;
else if (sel==3'b101)
f[2]=I;
else if (sel==3'b110)
f[1]=I;
else
f[0]=I;
end
endmodule
module fa (x,y,z,cout,sum);
input x,y,z;
output cout,sum;
wire P1,P2,P3;
Endmodule
module fulladd(cin,x,y,s,co);
input cin,x,y;
output s,co;
reg s,co;
always@(cin or x or y)
begin
case ({cin,x,y})
3'b000:{co,s}='b00;
3'b001:{co,s}='b01;
3'b010:{co,s}='b01;
3'b011:{co,s}='b10;
3'b100:{co,s}='b01;
3'b101:{co,s}='b10;
3'b110:{co,s}='b10;
3'b111:{co,s}='b11;
endcase
end
endmodule
module priority(w,y,f);
input [3:0] w;
output [1:0] y;
output f;
reg [1:0]y;
assign f=(w!=0);
always @(w)
begin
casex(w)
'b1xxx:y=3;
'b1xxx:y=2;
'b1xxx:y=1;
default:y=0;
endcase
end
endmodule
module updown(r,clk,l,e,u_d,q);
parameter n=8
input [n-1:0]r;
input clk,l,e,u_d;
output [n-1:0]q
reg [n-1:0]q;
integer dir;
always@(posedge clk)
begin
if (u_d)
dir=1;
else
dir=0;
if (l)
q<=r;
else if(e)
q<=Q+dir
end
endmodule