文本“for”附近的Verilog HDL语法错误;期待“endmodule”

时间:2018-03-13 04:08:04

标签: verilog quartus

 module alu(input logic [31:0] a, b,
              input logic [2:0] f,
             output logic [31:0] y,
             output logic zero);  

    wire [31:0] ANDed, ORed, SLT, sum, cout, bn;
    wire set_less;
    reg zero_detect;
    genvar i;

    //This segment will take 2s complement of B
    for(i = 0; i < 32; i = i+1) begin
     assign bn[i] = b[i] ^ f[2];
    end

    //This segment will compute the 32-bit addition
    assign sum[0] = (a[0] ^ bn[0]) ^ f[2];
    assign cout[0] =(a[0] & bn[0]) | ((a[0] ^ bn[0]) & f[2]);

    for(i = 1; i < 32; i = i +1) begin
     assign sum[i] = (a[i] ^ bn[i]) ^ cout[i-1];
     assign cout[i] = (a[i] & bn[i]) | ((a[i] ^ bn[i]) & cout[i-1]);
    end

    //This segment will complete the AND operation
    assign ANDed = a & bn;

    //This segment will complete the OR operation
    assign ORed = a | bn;

    //set less than, A < B then the first digit of the sum will be 1
    assign set_less = sum[31];
    assign SLT = {{31'b0000000000000000000000000000000}, set_less};

    //Set the zero flag if there aren't any 1's in the output
    assign zero = !(|y);

    //select the output based on the function input
    assign y = f[1] ? (f[0] ? SLT : sum )
                         : (f[0] ? ORed : ANDed);
    endmodule
  

错误(10170):文本附近alu.sv(15)的Verilog HDL语法错误:   “对于”;期待“endmodule”。检查并修复任何语法错误   出现在指定关键字之前或之前。

     

错误(10170):文本附近alu.sv(23)的Verilog HDL语法错误:   “对于”;期待“endmodule”。检查并修复任何语法错误   出现在指定关键字之前或之前。

     

错误(10170):文本附近alu.sv(26)的Verilog HDL语法错误:   “结束”;期待“endmodule”。检查并修复任何语法错误   出现在指定关键字之前或之前。

     

错误(10112):由于之前的原因,在alu.sv(4)处忽略了设计单元“alu”   错误

1 个答案:

答案 0 :(得分:-1)

genvar变量只能与生成块一起使用。在generate-endgenerate块中使用for循环来消除错误。