HBLbits_Verilog Basic_Bcdadd4
with a BCD (binary-coded decimal) one-digit adder named bcd_fadd that adds two BCD digits and carry-in, and produces a sum and carry-out.
module bcd_fadd { input [3:0] a, input [3:0] b, input cin, output cout, output [3:0] sum );
Instantiate 4 copies of bcd_fadd to create a 4-digit BCD ripple-carry adder.
module top_module(
input [15:0] a, b,
input cin,
output cout,
output [15:0] sum );
wire [2:0]ctmp;
bcd_fadd u0(a[3:0],b[3:0],cin,ctmp[0],sum[3:0]);
bcd_fadd u1(a[7:4],b[7:4],ctmp[0],ctmp[1],sum[7:4]);
bcd_fadd u2(a[11:8],b[11:8],ctmp[1],ctmp[2],sum[11:8]);
bcd_fadd u3(a[15:12],b[15:12],ctmp[2],cout,sum[15:12]);
endmodule
input cin,
output cout,
output [15:0] sum );
wire [2:0]ctmp;
bcd_fadd u0(a[3:0],b[3:0],cin,ctmp[0],sum[3:0]);
bcd_fadd u1(a[7:4],b[7:4],ctmp[0],ctmp[1],sum[7:4]);
bcd_fadd u2(a[11:8],b[11:8],ctmp[1],ctmp[2],sum[11:8]);
bcd_fadd u3(a[15:12],b[15:12],ctmp[2],cout,sum[15:12]);
endmodule
沒有留言:
張貼留言