Syntax 接收到以下错误:";第36行预期和#x27;endmodule';,发现';如果';

Syntax 接收到以下错误:";第36行预期和#x27;endmodule';,发现';如果';,syntax,verilog,Syntax,Verilog,在if(lr==0)的行中,我收到以下错误应为'endmodule',找到'if'。Verilog代码是一个8位移位寄存器,用作左移位器和右移位器,可以在算术移位和逻辑移位之间进行选择。我不明白为什么我会收到这个错误。这可能是某种语法错误,因为我是Verilog新手。提前谢谢你的帮助 module shifter( input [7:0] shift_in, input [2:0] shift_by, // 0 for left, 1 for right input lr, //0 fo

在if(lr==0)的行中,我收到以下错误应为'endmodule',找到'if'。Verilog代码是一个8位移位寄存器,用作左移位器和右移位器,可以在算术移位和逻辑移位之间进行选择。我不明白为什么我会收到这个错误。这可能是某种语法错误,因为我是Verilog新手。提前谢谢你的帮助

module shifter(
input [7:0] shift_in,
input [2:0] shift_by,

 // 0 for left, 1 for right
input lr,

 //0 for logical, 1 for arithmetic
input arith,
output reg signed [7:0] shift_out
);

//left shift
if(lr == 0) 
begin
    assign shift_out = shift_in << shift_by;
    assign shift_out[0] = 1'b0;
end
//right shift
else begin
    //logical shift
    if (arith == 0) begin
        assign shift_out = shift_in << shift_by;
        assign shift_out[7] = 1'b0;
    //arithmetic shift
    end else begin
        assign shift_out[7] = shift_in[7];
        assign shift_out = shift_in << shift_by;
    end
end

endmodule
模块移位器(
输入[7:0]shift_in,
输入[2:0]shift_by,
//0表示左侧,1表示右侧
输入lr,
//0表示逻辑,1表示算术
输入算术,
输出寄存器已签名[7:0]移出
);
//左移
如果(lr==0)
开始

assign shift_out=shift_in如果与assign类似,则不能使用。放置在“始终”块中,然后删除“指定”

always @* begin
//left shift
if(lr == 1'b0) 
begin
    shift_out = shift_in << shift_by;
    shift_out[0] = 1'b0;
end
//right shift
else begin
    //logical shift
    if (arith == 0) begin
        shift_out = shift_in << shift_by;
        shift_out[7] = 1'b0;
    //arithmetic shift
    end else begin
        shift_out[7] = shift_in[7];
        shift_out = shift_in << shift_by;
    end
end
end
始终@*开始
//左移
如果(lr==1'b0)
开始

shift_out=shift_in如果像assign这样的语句,则不能使用。放置在“始终”块中,然后删除“指定”

always @* begin
//left shift
if(lr == 1'b0) 
begin
    shift_out = shift_in << shift_by;
    shift_out[0] = 1'b0;
end
//right shift
else begin
    //logical shift
    if (arith == 0) begin
        shift_out = shift_in << shift_by;
        shift_out[7] = 1'b0;
    //arithmetic shift
    end else begin
        shift_out[7] = shift_in[7];
        shift_out = shift_in << shift_by;
    end
end
end
始终@*开始
//左移
如果(lr==1'b0)
开始
移出=移入