首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >接收以下错误:“第36行期待'endmodule',找到'if‘

接收以下错误:“第36行期待'endmodule',找到'if‘
EN

Stack Overflow用户
提问于 2015-02-12 07:39:07
回答 1查看 5.1K关注 0票数 0

在if(lr == 0)中,我收到了以下错误:“期待‘结束模块’,找到'if‘。Verilog代码是一个8位移位寄存器,充当左移位和右移位,可以在算术移位和逻辑移位之间进行选择。我看不出我为什么会收到这个错误。这可能是某种类型的语法错误,因为我对Verilog并不熟悉。谢谢事先提供的帮助。

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-02-12 09:22:21

如果在赋值中使用这样的状态,则不能使用。放置在一个始终块,并删除分配。

代码语言:javascript
复制
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
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28471861

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档