Verilog HDL 的2位BCD码加法器
begin
T0=A0+B0; //低位相加和值赋T0;
if(T0>9)
begin
Z0=10; //如果低位相加有进位,则赋值Z0=10;
C0=1; //如果T0>9,则有进位,此时C0=1;
end
else
begin
Z0=0;
C0=0;
end
begin
T1=A1+B1+C0; //高位为A1加B1再加进位C0,赋值给T1;
if(T1>9)
begin
Z1=10;
C1=1;
end
else
begin
Z1=0;
C1=0;
end
end
begin
S0=T0-Z0; //和值S0到S1赋值;
S1=T1-Z1;
S2=C1;
end
end
endmodule
2) 输入数A0、A1、B0、B1显示
module indisplay(A0,A1,B0,B1,displayA0,displayA1,displayB0,displayB1);
input [3:0]A0;
input [3:0]A1;
input [3:0]B0;
input [3:0]B1;
output [6:0]displayA0;
output [6:0]displayA1; //定义7段数码管的输出;
output [6:0]displayB0;
output [6:0]displayB1;