(編輯)我正在verilog算術項目和我卡在符號擴展部分(假設這是問題)。我有4位輸入A,B,應該有8位輸出。對於一些進程(總和,子...)我需要使用符號擴展來使8位輸出。所以對於算術的主體,我有這個代碼。這是代碼的一半。我不包括半部分cuz它只是長..verilog算術(符號擴展)編輯
module arithmetic(A, B, AN0, DP, sum, sub, mult, div, comp, shiftLeft,
shiftRight, signExtend);
input signed [3:0] A, B;
output [7:0] sum, sub, mult, div, comp, shiftLeft, shiftRight,
signExtend;
output AN0, DP;
//sum
reg [4:0] qsum;
[email protected] (A, B)
qsum = A+B;
assign sum = {{3{qsum[4]}},qsum};
//sub
reg [4:0] qsub;
[email protected] (A, B)
qsub = A-B;
assign sub = {{3{qsub[4]}},qsub};
//mult
reg [7:0] qmult;
[email protected] (A, B)
qmult = A * B;
assign mult = qmult;
,當我檢查我的模擬,它沒有任何價值,但Z,並且多個X。它甚至不顯示任何輸入值。爲什麼會這樣?謝謝
(編輯)這是我的測試平臺代碼。有8個操作(總和,減,乘,除法,比較器,shiftleft,shiftright,符號擴展)
module lap3_top_tb();
reg signed [3:0] A, B;
reg [2:0] Operation;
wire [7:0] Result;
wire DP, AN0;
lab3_top ulap3_top(
.A(A),
.B(B),
.Operation(Operation),
.Result(Result),
.DP(DP),
.AN0(AN0)
);
initial begin
A = 6; B = 7; Operation = 0;
#20;
A = -6; B = -7; Operation = 0;
#20;
A = 6; B = 7; Operation = 1;
#20;
A = -6; B = -7; Operation = 1;
#20;
A = 6; B = 7; Operation = 2;
#20;
A = -6; B = 7; Operation = 2;
#20;
A = 7; B = 4; Operation = 3;
#20;
A = 7; B = 0; Operation = 3;
#20;
A = 6; B = 7; Operation = 4;
#20;
A = -6; B = -7; Operation = 4;
#20;
A = 1; B = 6; Operation = 5;
#20;
A = 1; B = -6; Operation = 5;
#20;
A = 1; B = 6; Operation = 6;
#20;
A = 1; B = -6; Operation = 6;
#20;
A = 6; B = 0; Operation = 7;
#20;
A = -5; B = 0; Operation = 7;
#20;
end
endmodule
的lap3_top文件在這裏。 (mux_8_1會選擇直通結果輸出和縮小。如果你需要的代碼,讓我知道!但我想MUX正常工作)
module lap3_top(A, B, Operation, Result, AN0, DP);
input signed [3:0] A, B;
input [2:0] Operation;
output AN0, DP;
output [7:0] Result;
wire a, b, c, d, e, f, g, h;
arithmetic uarithmetic(
.A(A),
.B(B),
.AN0(AN0),
.DP(DP),
.sum(a),
.sub(b),
.mult(c),
.div(d),
.comp(e),
.shiftLeft(f),
.shiftRight(g),
.signExtend(h)
);
mux_8_1 umux8_1(
.A(a),
.B(b),
.C(c),
.D(d),
.E(e),
.F(f),
.G(g),
.H(h),
.Operation(Operation),
.Result(Result)
);
endmodule
非常感謝你的傢伙!
你好傑克,你能分享一些你的測試臺代碼嗎? –
你還可以發佈你的'lab3_top'模塊,看看'testbench'到'sum'模塊的所有連接嗎? – Roman