【发布时间】:2016-03-02 15:06:05
【问题描述】:
我正在研究 4 位进位超前我正在使用结构 Verilog。我很困惑,因为我正在实例化 4 个部分全加器,什么声明为输入,什么声明为线,总和去哪儿了?我知道这对某些人来说很容易,但我花了一些时间试图找出我的错误。我实现 pfa(部分全加器)的方式我有 a,b,carry 作为输入和 p(a * b) g(a xor b) 作为输出。这是我感到困惑的地方,进位是什么?是输入还是电线? 下面是我的代码,谢谢!
module pfa(a,b,c,sum,p,g); //A one PFA. I need 16 of them5
//wire w;
//reg a,b,c;
//wire sum,p,g;
input a,b,c;
output sum,p,g;
xor (w,a,b); //repeated P. May need it may not.
and (g,a,b); //Gi
xor (p,a,b); //Pi
xor (sum,w,c); //sum
endmodule
//input output
module fourBitPFA(A,B,Cin,P,G,Carry);
input [3:0] A,B;
input Cin;
output [3:0] S;
output Cout;
wire [3:0] P,G,carry;
wire p0,g0;
wire b1,b2,b3;
wire w,w1,w2,w3,w4,w5,w6,w7,w8,w9,w10,w11,w12;
wire c1,c2,c3,c4;
pfa PFA0(A[0],B[0],Cin,P[0],G[0],Carry[0]),
PFA1(A[1],B[1],C[1],P[1],G[1],C[1]),
PFA2(A[2],B[2],S[2],P[2],G[2],C[2]),
PFA3(A[3],B[3],S[3],P[3],G[3],C[3]);
//propagate
and (p0,P[3],P[2],P[1],P[0]);
//GENERATE
and (w,P[3],G[2]);
and (w1,P[3],P[2],G[1]);
and (w2,P[3],P[2],P[1],G[0]);
or (w,w1,w2);
//CLA
and (w3,P[0],Cin);
or (c1,G[0],w3);
and (w4,P[1],G[0]);
and (w5,P[1],P[0],Cin);
or (c2,G[1],w4,w5);
and (w6,P[2],G[1]);
and (w7,P[2],P[1],G[0]);
and (w8,P[2],P[1],P[0],Cin);
or (c3,G[2],w6,w7,w8);
and (w9,P[3],G[2]);
and (w10,P[3],P[2],G[1]);
and (w11,P[3],P[2],P[1],G[0]);
and (w12,P[3],P[2],P[1],P[0],Cin);
or(c4,w9,w10,w11,w12);
endmodule
【问题讨论】:
标签: verilog