2017-04-14 322 views
0

(編輯)我正在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 

非常感謝你的傢伙!

+1

你好傑克,你能分享一些你的測試臺代碼嗎? –

+0

你還可以發佈你的'lab3_top'模塊,看看'testbench'到'sum'模塊的所有連接嗎? – Roman

回答

0

我嘗試模仿你的代碼,發現代碼中的以下錯誤:當你測試臺模塊中實例化頂層模塊使用lab3_top ulap3_top(...);b 3_top模塊的名稱,但模塊,你想有另一個名字module lap3_top(...); la p 3_top。

我改了名字,並一切正常(上波形可以看到ZZ狀態, 因爲我的代碼和幾個操作都沒有說明不mux_8_1模塊)enter image description here

附:順便說一句,我想你在添加這個標籤時使用Vivado。如果是這樣,有一個提示如何檢查這樣的錯誤(在模塊和實例化中有不同的名稱,或者當模塊中有一些錯誤時,它不能在庫中編譯)。如果將所有模塊擴展爲層次結構,則會發現?登錄模塊出現錯誤。 enter image description here

+0

哇..我花了很多時間在這個錯誤..謝謝! – Jake

+0

不客氣! – Roman

+0

@Jake我還添加了更多信息,我希望在未來的Vivado工作中可以幫助您 – Roman