2016-09-30 63 views
-1

我目前正在使用Quartus 16.0開展關於ALU的任務。作爲Verilog的初學者,由於缺乏相關知識,我真的很難過。 試圖很難找到代碼中的問題,但仍需要幫助。Verilog錯誤:期待一個冒號,並期待一個等號

reg [7:0] ALUout; 
    [email protected](*) 
    begin 
    case(keys[2:0]) 
    3'b000: add plus(.a0(a0), .a1(a1), .a2(a2), .a3(a3), .b0(b0), .b1(b1), .b2(b2), .b3(b3), .s0(ALUout[0]), .s1(ALUout[1]), .s2(ALUout[2]), .s3(ALUout[3]), .cout(ALUout[4])); 
    3'b001: ALUout = A + B; 
    3'b010: ALUout = {A | B, A^B}; 
    3'b011: function3 u0(.a0(a0), .a1(a1), .a2(a2), .a3(a3), .b0(b0), .b1(b1), .b2(b2), .b3(b3), .Out(ALUout)); 
    3'b100: function4 u1(.a0(a0), .a1(a1), .a2(a2), .a3(a3), .b0(b0), .b1(b1), .b2(b2), .b3(b3), .Out(ALUout)); 
    endcase 
end 

這裏的錯誤消息:

錯誤(10170):在Lab3Part3.v Verilog HDL語言語法錯誤(274)附近的文字: 「加」;期待「< =」或「=」。

錯誤(10170):Lab3Part3.v(274)附近出現Verilog HDL語法錯誤:「;」;期待「:」或「,」。

和其他行相同。

到目前爲止,我只是在課堂上學到了一點總是封閉的,幾乎沒有案例陳述,請幫忙。任何幫助將不勝感激。

回答

0

您不能在程序塊內實例化模塊。在always塊外部移動模塊實例,並將模塊的輸出連接到適當寬度的導線。在always塊中,引用電線。

另外,ALUout需要在always塊內的所有可能的組合中具有已知的分配。否則可以推斷出複雜的鎖存器。應使用default來處理具有值5,6或7的keys[2:0]的條件。

reg [7:0] ALUout; 
wire [4:0] add_out; 
wire [7:0] func3_out, func4_out; 
add plus(.a0(a0), .a1(a1), .a2(a2), .a3(a3), .b0(b0), .b1(b1), .b2(b2), .b3(b3), .s0(add_out[0]), .s1(add_out[1]), .s2(add_out[2]), .s3(add_out[3]), .cout(add_out[4])); 
function3 u0(.a0(a0), .a1(a1), .a2(a2), .a3(a3), .b0(b0), .b1(b1), .b2(b2), .b3(b3), .Out(func3_out)); 
function4 u1(.a0(a0), .a1(a1), .a2(a2), .a3(a3), .b0(b0), .b1(b1), .b2(b2), .b3(b3), .Out(func4_out)); 
[email protected](*) 
    begin 
    case(keys[2:0]) 
    3'b000: ALUout = {3'b0,add_out}; // leading zero padding 
    3'b001: ALUout = A + B; 
    3'b010: ALUout = {A | B, A^B}; 
    3'b011: ALUout = func3_out; 
    3'b100: ALUout = func4_out; 
    default: ALUout = 8'b0; // without this like ALUout would be an inferred latch 
    endcase 
end