这是我的代码:(我试图制作一个简单的 4x4 数组乘法器)
我定义了一个全加器,然后我定义了一个基本块,它由一个全加器和一个and
门组成。
代码正文:
// MODULE
//Set the measurement and percesion of time
`timescale 1ns / 1ps
//Create a module for Full Adder and define all the inputs, outputs and wires involved
module FA_struct(a, b, c_in, sum, c_out);
input a, b, c_in;
output sum, c_out;
wire w1,w2,w3;
xor (w1, a, b);
xor (sum, w1, c_in);
and (w2, a, b);
and (w3, w1, c_in);
or (c_out, w3, w2);
endmodule
//Basic Block structure
module BB_struct(a, b, pp, c_in, sum, c_out);
input a, b, pp, c_in;
output sum, c_out;
wire w1;
and (w1, a, b);
FA_struct basic_block(w1, pp, c_in, sum, c_out);
endmodule
module array_multiplier(A, B, prod);
input[3:0] A, B;
output[7:0] prod;
wire[3:0] c0, c1, c2, c3;
wire[3:0] s0, s1, s2;
assign a = 0;
BB_struct l00 (A[0], B[0], a, a, prod[0], c0[0]);
BB_struct l01 (A[1], B[0], a, a, s0[1], c0[1]);
BB_struct l10 (A[0], B[1], s0[1], a, prod[1], c1[0]);
BB_struct l02 (A[2], B[0], a, a, s0[2], c0[2]);
BB_struct l11 (A[1], B[1], s0[2], c1[0], s1[1], c1[1]);
BB_struct l20 (A[0], B[2], s1[1], a, prod[2], c2[0]);
BB_struct l03 (A[3], B[0], a, a, s0[3], c0[3]);
BB_struct l12 (A[2], B[1], s0[3], c1[1], s1[2], c1[2]);
BB_struct l21 (A[1], B[2], s1[2], c2[0], s2[1], c2[1]);
BB_struct l30 (A[0], B[3], s2[1], a, prod[3], c3[0]);
BB_struct l13 (A[3], B[1], a, c1[2], s1[3], c1[3]);
BB_struct l22 (A[2], B[2], s1[3], c2[1], s2[2], c2[3]);
BB_struct l31 (A[1], B[3], s2[2], c3[0], prod[4], c3[1]);
BB_struct l23 (A[3], B[2], c1[3], c2[2], s2[3], c2[3]);
BB_struct l32 (A[2], B[3], s2[3], c3[1], prod[5], c3[2]);
BB_struct l33 (A[3], B[3], a, c2[3], prod[6], prod[7]);
endmodule
这是我的测试台
//TestBench
module AM_tb();
reg[3:0] A, B;
wire[7:0] prod;
array_multiplier amtb (A, B, prod);
initial begin
$dumpfile("amtb.ved");
$dumpvars(0, amtb);
#0 A = 4'b1001; B = 4'b0001;
#10 A = 4'b1110; B = 4'b1010;
#10 A = 4'b1111; B = 4'b0000;
#10 A = 4'b1011; B = 4'b1011;
end
initial begin
$monitor("%d: A = %b B = %b product = %b ",$time, A, B, prod); //Display
end
endmodule
输出:我不知道为什么我在产品的某些位置得到“x”。
VCD info: dumpfile amtb.ved opened for output.
0: A = 1001 B = 0001 product = 00x01001
10: A = 1110 B = 1010 product = 01x01100
20: A = 1111 B = 0000 product = 00x00000
30: A = 1011 B = 1011 product = xxx11001