【发布时间】:2014-03-09 21:37:59
【问题描述】:
我让我的 2 位加法器工作,但由于某种原因它没有通过进位位。例如,如果我使用 A=1 和 B=1,则结果 S=00,但如果 A 或 B 为 1,我得到 S=1 ?我尝试打印出这些值,似乎我在第二个模块中的 c1 线没有被设置,并且由于某种原因 Cout 是。
所以输入 A=1、B=1、S=00 和 Cout=1 什么时候应该。 S=10 和 Cout=0
我只使用 Verilog 一天,所以语法对我来说很新。
module fulladder(Cin,A,B,S,Cout); // dont forget semi colon
input A,B, Cin; // defaults to 1 bit or [0,0] size
output S, Cout;
wire XOR1,AND1,AND2;
xor(XOR1,A,B);
and(AND1,A,B);
xor(S,Cin,XOR1);
and(AND2,Cin,XOR1);
or(Cout,AND2,AND1);
endmodule
module adder4(Cin,A,B,S,Cout);
input Cin;
input [0:1]A;
input [0:1]B;
output [0:1]S;
output Cout;
wire c1;
fulladder FA1(Cin,A[0:0],B[0:0],S[0:0],c1);
fulladder FA2(c1,A[1:1],B[1:1],S[1:1],Cout);
endmodule
module t_adder;
reg Cin;
reg [1:0]A;
reg [1:0]B;// to declare size, must be on own line, wires can be more than 1 bit
wire [1:0]S;
wire Cout;
adder4 add4bit(Cin,A,B,S,Cout);
initial
begin
A = 1; B = 1; Cin = 0;
#1$display("S=%b Cout = %b",S,Cout);
end
endmodule
【问题讨论】: