代码如下:
module fulladder(a,b,ci,co,sum);
input a,b,ci;
output co,sum;
assign sum=a^b^ci;
assign co=(a&b)|(a&ci)|(b&ci);
endmodule
module FBitFadder(a,b,overf,result);
input[3:0] a;
input[3:0] b;
output[3:0] result;
output overf;
wire[2:0] c;
fulladder adder1(a[0],b[0],0,c[0],result[0]);
fulladder adder2(a[1],b[1],c[0],c[1],result[1]);
fulladder adder3(a[2],b[2],c[1],c[2],result[2]);
fulladder adder4(a[3],b[3],c[2],overf,result[3]);
endmodule
TestBech如下:
`
timescale 1 ns/ 1 ps
module FBitFadder_vlg_tst();
// constants
// general purpose registers
reg eachvec;
// test vector input registers
reg [3:0] a;
reg [3:0] b;
// wires
wire overf;
wire [3:0] result;
// assign statements (if any)
FBitFadder i1 (
// port map - connection between master ports and signals/registers
.a(a),
.b(b),
.overf(overf),
.result(result)
);
initial
begin
// code that executes only once
// insert code here --> begin
a=0;
b=0;
#100;
a=4'b1000;
b=4'b1001;
#100;
a=4'b1011;
b=4'b1001;
#100;
a=4'b0110;
b=4'b0011;
// --> end
$display("Running testbench");
end
endmodule
一周热门 更多>