我是一名初學者,我想用generate塊編寫一個紋波進位加法器。所以我寫了以下模塊:使用verilog生成所有輸出的紋波進位加法器X
module ripple_carry_adder(ia, ib, ci, so, co);
parameter N = 32;
input[N-1:0] ia;
input[N-1:0] ib;
input ci;
output[N-1:0] so;
output co;
wire [N:0] carry;
assign carry[0] = ci;
genvar j;
generate for(j = 0; j < N; j = j + 1)
begin:r_loop
wire t1, t2, t3;
xor g1(t1, ia[i], ib[j]);
xor g2(so[j], t1, carry[j]);
and g3(t2, ia[i], ib[j]);
and g4(t3, t1, carry[j]);
or g5(carry[j+1], t2, t3);
end
endgenerate
assign co = carry[N];
endmodule
而且測試臺模塊:
`include "ripple_carry_adder.v"
`timescale 1ns/1ps
module ripple_carry_adder_tb;
parameter N = 32;
reg clk;
reg[N-1:0] a, b;
wire[N-1:0] sum;
reg cin;
wire cout;
ripple_carry_adder rca(.ia(a), .ib(b), .ci(cin), .so(sum), .co(cout));
initial begin
#10;
a = 0;
b = 0;
cin = 0;
clk = 0;
#10;
end
always @(posedge clk)
begin
#50;
#1 a <= $random() % 1000000;
#1 b <= $random() % 1000000;
end
always @(a or b)
#5 $display("%d + %d = %d", a, b, sum);
always #5 clk = ~clk;
endmodule
但我得到了與未知的所有位的結果: result
我白白花了1小時嘗試找到錯誤。你可以幫我嗎?
的'i'在'IA得到default_nettype更多詳情[I]'是不確定的。未定義的變量推斷出單個位線。也許你的意思是'j'? – Greg
天啊!非常感謝 ! –
但是很奇怪,這個編譯器甚至沒有提示一個警告:( –