Booth编码不起作用,包括模拟

时间:2012-02-17 04:42:16

标签: verilog system-verilog modelsim

我正在编写一个用于数组乘法器的Booth编码。这是模块之一:

module add_input (M,pos,neg,C);
parameter n=8;

input  [n-1:0]M;
input  pos,neg;

output [2*n-1:0]C;
reg [2*n-1:0]C;

integer k;

always @ (*)
begin
 for (k=0;k<=n-1;k=k+1)
 begin
   C[k]=(pos& (M[k]))|((~M[k])&neg);
 end
   C[2*n-1:n]={n{C[n-1]}};
end

endmodule

此模块的测试平台模拟正常:

a busy cat http://img39.imageshack.us/img39/3444/74546414.jpg

但是,当我将此模块放入顶层设计时,我看不到模块add_input的任何输出。真的想知道为什么,整晚都在调试这个。

代码:

module Array_Mutiplier (M,Q,outcome, t_pos, t_neg,t_Y1);
parameter n=8;
parameter m=16;
input [n-1:0]M,Q;
output [m-1:0]outcome;

//-----------------------------------------------------------
output [n-1:0] t_pos, t_neg;
output [m-1:0] t_Y1;
//-----------------------------------------------------------
//first part, got the booth code
wire [n-1:0]negative,positive;
booth_encode BE(Q,positive,negative);

//get the Y for the full adder
wire [m-1:0]Y1;
add_input row_1 (M,positive[0],negative[0],Y1);
wire [2*n-1:0]Y2;
add_input row_2 (M,positive[1],negative[1],Y2);
wire [2*n-1:0]Y3;
add_input row_3 (M,positive[2],negative[2],Y3);
wire [2*n-1:0]Y4;
add_input row_4 (M,positive[3],negative[3],Y4);
wire [2*n-1:0]Y5;
add_input row_5 (M,positive[4],negative[4],Y5);
wire [2*n-1:0]Y6;
add_input row_6 (M,positive[5],negative[5],Y6);
wire [2*n-1:0]Y7;
add_input row_7 (M,positive[6],negative[6],Y7);
wire [2*n-1:0]Y8;
add_input row_8 (M,positive[7],negative[7],Y8);


assign t_pos=positive;
assign t_neg=negative;
assign t_Y1=Y1;

endmodule

a busy cat http://img855.imageshack.us/img855/3361/28395154.png

根据模拟,您可以看到booth编码器工作正常,但为什么输出t_Y1始终为0?

1 个答案:

答案 0 :(得分:1)

从第二个波形开始,t_pos [0]和t_neg [0]都为零,这意味着正[0]和负[0]也都为零。在row_1实例中,pos和neg为零,这意味着C [7:0]的所有位都为零((pos& (M[k]))|((~M[k])&neg)计算为0)。由于C [7] = 0,这意味着C [15:8] = 0,因此C [15:0] = 0,Y1和t_Y1也为零。