syntax-error - 如何编写连续的案例陈述?

标签 syntax-error verilog

我得到了一个任务,在Verilog中使用未签名的输入制作一个4位的展位乘法器。
在此之前,我仅使用过verilog几次,因此我不太熟悉在其中编写case语句的情况。

module booth(ina,inb,out);

   input [3:0] ina, inb;
   output[7:0] out;
    reg[2:0] p1,p2;
    reg[5:0] temp1, temp2;

assign p1={inb[2],inb[1],0};
assign p2={inb[3],inb[2],inb[1]};   
    
always @(*)
begin
out = 8'b00000000;
case(p1)
3'b000: temp1=0;
3'b010: temp1=ina;
3'b100:temp1=-2 * ina;
3'b110:temp1= -ina; 
endcase 
end

begin
case(p2)
3'b000,3'b111: temp2=0;
3'b001,3'b010: temp2=ina;
3'b011:temp2=2 * ina;
3'b100:temp2=-2 * ina;
3'b101,3'b110:temp2= -ina;  
endcase
temp2 = temp2<<2;
end

assign out=temp1+temp2;
endmodule
我应该如何连续写两个case语句?
我收到语法错误:

syntax error near text: "begin"; expecting "endmodule". Check for and fix any syntax errors that appear immediately before or at the specified keyword.

最佳答案

有几个编译错误。
您的错误消息可能引用了begin/end语句后的2个连续的always块。解决此问题的一种方法是添加第二个always语句。以此方式分隔temp1temp2逻辑是一个好主意。
我也收到p1的错误,因为您使用assign语句对其进行了连续分配。您应该将信号声明为wire而不是reg。更改:

   reg [2:0]    p1,p2;
至:
   wire [2:0]    p1,p2;
另一个问题是您对out信号进行了多次分配。我认为您可能希望将其从always块中删除。
最后,您需要在p1语句中将大小常量设为0。更改:
   assign p1={inb[2],inb[1],0};
至:
   assign p1={inb[2],inb[1],1'b0};
这段代码可以为我干净地编译:
module booth(ina,inb,out);

   input [3:0] ina, inb;
   output [7:0] out;
   wire [2:0]    p1,p2;
   reg [5:0]    temp1, temp2;

   assign p1={inb[2],inb[1],1'b0};
   assign p2={inb[3],inb[2],inb[1]};   
   
   always @(*) begin
        case(p1)
          3'b000: temp1=0;
          3'b010: temp1=ina;
          3'b100:temp1=-2 * ina;
          3'b110:temp1= -ina; 
        endcase 
     end

   always @(*) begin
      case(p2)
        3'b000,3'b111: temp2=0;
        3'b001,3'b010: temp2=ina;
        3'b011:temp2=2 * ina;
        3'b100:temp2=-2 * ina;
        3'b101,3'b110:temp2= -ina;  
      endcase
      temp2 = temp2<<2;
   end

   assign out=temp1+temp2;
endmodule

关于syntax-error - 如何编写连续的案例陈述?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65764427/

相关文章:

python - 在PyTorch中将root =设置为时,语法无效

ms-access - 使用存储过程的查询表达式中的语法错误(缺少运算符)

javascript - “Uncaught SyntaxError: Unexpected token <”(等等,还有更多!)

verilog - `定义宏的范围

verilog - 如何监控SystemVerilog程序 block 中的信号

verilog - 系统 Verilog 中基于参数的类型定义

vba - 为什么这条线没有抛出错误: str strVariable = "text"

verilog - 将枚举转换为逻辑

verilog - 数据存储单元

asp.net-mvc - ASP.NET MVC Razor语法错误