【发布时间】:2012-11-11 15:54:27
【问题描述】:
我已经写了下面的代码。
我的问题:
在索引 1
它以一些值进入 for 循环。它出现在“if”语句中,正如您所见,每个“if”的最后一条指令类似于“P=....”。
在索引 2(下一步)
它进入'if'语句,但P的值不是来自步骤1,它是初始值。
如何在下一步使用“P”的最后一个值? (索引+1)
module multiplier(prod, a, b, wireP, wireA, wireS);
output [15:0] prod;
output [16:0] wireA;
output [16:0] wireS;
output [16:0] wireP;
reg [15:0] prod;
input [7:0] a;
input [7:0] b;
reg [16:0] P;
reg [16:0] S;
reg [16:0] A;
wire [16:0] tempshift;
reg [16:0] tempoutshift;
arithmeticShift shiftP(tempshift,P);
wire [16:0] tempPS;
reg [16:0] tempoutPS;
carryForPbooth sumPS(coutPS,tempPS,P,S,0);
wire [16:0]tempPA;
reg [16:0]tempoutPA;
carryForPbooth sumPA(coutPA,tempPA,P,A,0);
reg [16:0] regP;
reg [16:0] regA;
reg [16:0] regS;
integer index;
always @(*) begin
A[16:9] = a[7:0];
A[8:0] = 9'b000000000;
S[16:9] = ~a[7:0]+1'b1;
S[8:0] = 9'b000000000;
P[16:9] = 8'b00000000;
P[8:1] = b[7:0];
P[0] = 1'b0;
#1 tempoutPS = tempPS;
#1 tempoutPA = tempPA;
#1 tempoutshift = tempshift;
for(index = 1; index < 9; index = index + 1) begin
if((P[1:0] == 2'b00) | (P[1:0] == 2'b11)) begin
#1 tempoutshift = tempshift;
#1 P = tempoutshift;
end
if(P[1:0] == 2'b01) begin
#1 tempoutPA = tempPA;
#1 P = tempoutPA;
#1 tempoutshift = tempshift;
#1 P = tempoutshift;
end
if(P[1:0] == 2'b10) begin
#1 tempoutPS = tempPS;
#1 P = tempoutPS;
#1 tempoutshift = tempshift;
#1 P = tempoutshift;
end
end
#1 prod=P[16:1];
end
assign wireP = P;
assign wireS = S;
assign wireA = A;
endmodule
【问题讨论】:
-
您有
input [7:0] a;和reg [16:0] A;仅按大小写区分变量通常是个坏主意。有些模拟器不区分大小写。 -
这是一个测试台组件还是 RTL?
#1将无法合成。 -
这是否意味着在 9 个时钟周期内进行移位和相加乘法?
标签: simulation verilog xilinx