2012-10-28 64 views
0

我試圖儘快做出24根電線,但我總是收到錯誤:如何在Verilog中快速製作多條電線?

錯誤(10170):your_ALU_mux.v(81)附近的文本「=」出現Verilog HDL語法錯誤; 「」 期待,或標識

這裏是我的代碼:

module your_ALU_mux(your_out, operandA, operandB, opcode, switches, address); 
input [7:0] operandA, operandB, address; 
input [3:0] opcode, switches; 
output [7:0] your_out; 

wire [0:7] Bnot, newb, newa; 
wire Cin, Cout; 

    not 
     (Bnot[0], operandB[0]), 
     (Bnot[1], operandB[1]), 
     (Bnot[2], operandB[2]), 
     (Bnot[3], operandB[3]), 
     (Bnot[4], operandB[4]), 
     (Bnot[5], operandB[5]), 
     (Bnot[6], operandB[6]), 
     (Bnot[7], operandB[7]); 

// Getting A' and B' 
    if (address == 16'h00 || address == 16'h01) 
    // Add A + B 
    if (address == 16'h00) 

     // newa = A 
     newa[0] = operandA[0]; 
     newa[1] = operandA[1]; 
     newa[2] = operandA[2]; 
     newa[3] = operandA[3]; 
     newa[4] = operandA[4]; 
     newa[5] = operandA[5]; 
     newa[6] = operandA[6]; 
     newa[7] = operandA[7]; 

     // newb = B' 
     newb[0] = Bnot[0]; 
     newb[1] = Bnot[1]; 
     newb[2] = Bnot[2]; 
     newb[3] = Bnot[3]; 
     newb[4] = Bnot[4]; 
     newb[5] = Bnot[5]; 
     newb[6] = Bnot[6]; 
     newb[7] = Bnot[7]; 

     // Carry in = 1 
     Cin = 1; 


     // A-B 
    else if (address == 16'h01) 
     // newb = B 
     newb[0] = operandB[0]; 
     newb[1] = operandB[1]; 
     newb[2] = operandB[2]; 
     newb[3] = operandB[3]; 
     newb[4] = operandB[4]; 
     newb[5] = operandB[5]; 
     newb[6] = operandB[6]; 
     newb[7] = operandB[7]; 

     // newa = A 
     newa[0] = operandA[0]; 
     newa[1] = operandA[1]; 
     newa[2] = operandA[2]; 
     newa[3] = operandA[3]; 
     newa[4] = operandA[4]; 
     newa[5] = operandA[5]; 
     newa[6] = operandA[6]; 
     newa[7] = operandA[7]; 

     // Carry in = 0 
     Cin = 0; 



end 
     RippleCarryAdd A+B(.S0(your_out[0]), .S1(your_out[1],.S2(your_out[2],.S3(your_out[3],.S4(your_out[4],.S5(your_out[5] 
            S6.(your_out[6]), S7.(your_out[7], 
            .Cout(Cout),.Cin(Cin), 
            .A0(newa[0]),.A1(newa[1]),.A2(newa[2]),.A3(newa[3]),.A4(newa[4]),.A5(newa[5]), 
            .A6(newa[6]),.A7(newa[7]), 
            .B0(newb[0]),.B1(newb[1]),.B2(newb[2]),.B3(newb[3]),.B4(newb[4]), 
            .B5(newb[5]),.B6(newb[6]),.B7(newb[7])); 

endmodule 

我也得到錯誤說:

錯誤(10170):在your_ALU_mux.v Verilog HDL語言語法錯誤(66 )接近文字「if」;期待「endmodule」

而它把我帶到我的第一條if語句。

這是錯誤的方式去創建電線和他們使用它們?

+0

'A + B'是一個非法的標識符名稱 - 實例名稱不允許帶符號'+','-'等 – Marty

回答

0
  • if報表時需要的是一個always塊內,他們不能僅僅是模塊的一部分
  • 當寫多,如果情況下,你需要用報表beginend語句(考慮它們類似於{}其他編程語言)
  • 你似乎在RippleCarryAdd
之前有一個隨機 end聲明沒有
+0

如果在'always'塊內進行評估,請不要忘記聲明爲'reg' 。 – Morgan

2

爲了使你的代碼更緊湊,你知道:

always @* begin 
    newa[0] = operandA[0]; 
    newa[1] = operandA[1]; 
    newa[2] = operandA[2]; 
    newa[3] = operandA[3]; 
    newa[4] = operandA[4]; 
    newa[5] = operandA[5]; 
    newa[6] = operandA[6]; 
    newa[7] = operandA[7]; 
end 

是一樣的:

reg newa[7:0] 
always @* begin 
    newa[7:0] = operandA[7:0]; 
end 

爲線:

wire newa[7:0] 
assign newa[7:0] = operandA[7:0]; 

位選擇[7:0]是可選的,如果使用全寬。