Documente Academic
Documente Profesional
Documente Cultură
p=~l;
not(a0_n,a0);
t=p&c;
not(a1_n,a1);
l=a^b;
not(a2_n,a2);
m=a_n&b;
and(y0,a0_n,a1_n,a2_n);
diff=p^c;
and(y1,a2_n,a1_n,a0);
borrow=t|m;
and(y2,a2_n,a1,a0_n);
end
and(y3,a2_n,a1,a0);
endmodule
and(y4,a2,a1_n,a0_n);
and(y5,a2,a1_n,a0); and(y2,d,s0_n,s1);
and(y6,a0_n,a1,a2); and(y3,d,s0,s1);
and(y7,a0,a1,a2);
endmodule
endmodule
always@(*)
input[3:0]a;
begin
wire[3:0]a;
y=s0?(s1?d:c):(s1?b:a);
input[3:0]b;
end
wire[3:0]b;
end module
DeMux integer i;
module demux(s1,s0,d,y0,y1,y2,y3);
input din ;
wire din ;
input clk ;
SIPO
wire clk ;
input reset ; module SIPO ( din ,clk ,reset
wire reset ; ,dout );
not(a0_n,a0);
4 bit up/down counter not(b0_n,b0);
module counter4bit(clk,reset,dout); and(a1,b_n,a);
input clk,reset; and(a2,a0,b_n);
output [3:0]dout; and(a3,a0,a);
reg[3:0]dout; and(a4,b,a_n);
wire clk,reset;
and(a5,b0,b,a0_n);
initial dout=0;
and(a6,a_n,a0_n,b0);
always@(posedge(clk))
xnor(a7,a,b);
begin
xnor(a8,b0,a0);
if(reset)
or(b1,a2,a3);
dout<=0;
and(b2,b1,b0_n);
else
or(y0,b2,a1);
dout<=dout+1;
or(y1,a4,a5,a6);
end
and(y2,a7,a8);
endmodule
endmodule
wire enable ;
input din ;
4 bit counter wire din ;
module counter4bit(clk,reset,dout); input reset ;
input clk,reset; wire reset ;
output [3:0]dout;
dout = 0;
initial dout=0; else begin
if (enable)
always@(posedge(clk)) dout = din;
begin end
if(reset) end
dout<=0;
else endmodule
dout<=dout+1;
end
decoder
endmodule module d_latch ( enable ,din ,reset ,dout );
output dout ;
d latch reg dout ;
input enable ;
wire din ;
if (reset)
d-flipflop
dout = 0;
module dflipflop (din,clk,reset,dout);
else begin
input din,clk,reset;
if (enable)
output dout;
dout = din;
reg dout;
end
always@(posedge clk)
end
begin
if(reset)
endmodule
dout<=1;
else
demux dout<=din;
output y0,y1,y2,y3;
wire s1_n;
wire s0_n;
input[3:0]a;
endmodule
wire[3:0]a;
input[3:0]b; not(a1_n,a1);
wire[3:0]b; not(a_n,a);
and(b2,a,b);
integer i; and(b1,a1_n,c);
or(borrow,b1,b2);
reg[4:0]s;
s[0] = 0;
for(i=0;i<3;i=i+1) begin
full subtractor
sum[i]=a[i]^b[i]^s[i]; module fullsubtractor (a,b,c,diff,borrow);
begin
end a_n=~a;
endmodule p=~l;
t=p&c;
l=a^b;
diff=p^c;
module full_subtractor(a,b,c,diff,borrow);
borrow=t|m;
input a,b,c;
end
output diff,borrow;
endmodule
wire a_n;
input k ;
xor(difference,a,b); wire k ;
always@(a or b) qb <= 1;
begin end
borrow=a_n&b; q <= j;
end qb <= k;
endmodule end
q <= ~q;
jk ff qb <= ~qb;
module jk_flipflop ( j ,k ,clk ,reset ,q ,qb ); end
end
output q ; end
reg q ;
output qb ;
reg qb ; endmodule
input j ;
tflipflop
mux module t_flipflop ( t ,clk ,reset ,dout );
module mux(mux_out,i0,i1,i2,i3,select);
output dout ;
input i0,i1,i2,i3;
reg dout ;
output mux_out;
input[1:0] select;
input t ;
reg mux_out;
wire t ;
always@(select,i0,i1,i2,i3)
input clk ;
case(select)
wire clk ;
2'b00: mux_out=i0;
input reset ;
2'b01: mux_out=i1;
wire reset ;
2'b10: mux_out=i2;
2'b11: mux_out=i3;
initial dout = 0;
endcase
dout <= 0;
module muxxx(a,b,c,d,s0,s1,y);
else begin
input a,b,c d,s0,s1;
if (t)
output y;
dout <= ~dout;
reg y;
end
always @(*)
end
begin
y=s0?(s1?d:c):(s1?b:a);
endmodule
end
end module