Xlinkslib
Xlinkslib
Xlinkslib
input s;
input r;
input clk;
output q;
output qb;
reg q,qb;
always@(posedge clk)
begin
if(s==0&r==0)
q=0;
else if(s==0&r==1)
q=0;
else if(s==1&r==0)
q=1;
else if(s==1&r==1)
q=1'bx;
qb=~q;
end
endmodule
module jkflipflop_v;
reg j;
reg k;
reg clk;
wire q;
wire qb;
jk uut (
.j(j),
.k(k),
.clk(clk),
.q(q),
.qb(qb)
);
initial begin
j = 0;
k = 0;
clk = 0;
end
initial begin
forever begin
#10 clk=~clk;
end
end
initial begin
j=0;k=0;
#20 $display("q=%b,qb=%b",q,qb);
j=0;k=1;
#20 $display("q=%b,qb=%b",q,qb);
j=1;k=0;
#20 $display("q=%b,qb=%b",q,qb);
j=1;k=1;
#20 $display("q=%b,qb=%b",q,qb);
end
endmodule
module dflipflop_v;
reg d;
reg clk;
wire q;
wire qb;
dff uut (
.d(d),
.clk(clk),
.q(q),
.qb(qb)
);
initial begin
d = 0;
clk = 0;
end
initial begin
forever begin
#10 clk=~clk;
end
end
initial begin
d=0;
#20 $display ("q=%b,qb=%b",q,qb);
d=1;
#20 $display ("q=%b,qb=%b",q,qb);
end
endmodule
module Asynchronouscounter_v;
reg clk;
reg res;
wire [3:0] q;
count uut (
.clk(clk),
.res(res),
.q(q)
);
initial begin
clk = 0;
res = 0;
end
initial begin
forever begin
#5 clk=~clk;
end
end
initial begin
res=0;
$monitor("q=%d",q);
#160 res=1;
$monitor("q=%d",q);
#160 $finish;
end
endmodule
module 4bitadder_v;
reg [3:0] a;
reg [3:0] b;
reg cin;
wire [3:0] s;
wire cout;
bit uut (
.a(a),
.b(b),
.cin(cin),
.s(s),
.cout(cout)
);
initial begin
a = 0;
b = 0;
cin = 0;
end
initial begin
a=4'b0101 ; b=4'b0100;
#40 $display("S=%b,cout=%b",s,cout);
a=4'b0001 ; b=4'b1110;
#40 $display("S=%b,cout=%b",s,cout);
a=4'b1010 ; b=4'b0101; cin=1'b1;
#40 $display("S=%b,cout=%b",s,cout);
#20 $finish;
end
endmodule
module 32bitalu_v;
reg [31:0] a;
reg [31:0] b;
reg [2:0] opcode;
reg en;
wire [31:0] y;
wire [63:0] y_mul;
alu uut (
.a(a),
.b(b),
.opcode(opcode),
.en(en),
.y(y),
.y_mul(y_mul)
);
initial begin
a = 32'd100;
b = 32'd140;
opcode = 0;
en = 1;
end
initial begin
#20 opcode = 3'd0;
#20 opcode = 3'd1;
#20 opcode = 3'd2;
#20 opcode = 3'd3;
#20 opcode = 3'd4;
#20 opcode = 3'd5;
#20 opcode = 3'd6;
#20 opcode = 3'd7;
end
endmodule