Error (10170):mult.v(9) 的 Verilog HDL 语法错误靠近文本“=”;期待“。”,或标识符,或“[”

问题描述 投票:0回答:1

我正在尝试实现这个问题中提到的电路:How to perform right shifting binary multiplication?

我收到错误:

错误 (10170):mult.v(9) 文本“=”附近的 Verilog HDL 语法错误;期待“。”,或标识符,或“[”

我试着用谷歌搜索它,但找不到任何东西

代码:

module mult (multiplier, multiplicand, result, clk);

input [3:0] multiplier;
input [4:0] multiplicand;
input clk;
output [8:0] result;
reg [8:0] product;

initial
begin
    product [8:4] = 4'b00000;
    product [3:0] = multiplier [3:0];
end

assign result = product;

always @ (posedge clk)
begin
    if (product[0] == 1)
    begin
        product = product >> 1; // shift right, and assign the most significant bit to 0
        product[8:4] = product[7:3] + multiplicand[4:0]; // add 5-bits so we can handle the carry-out
    end
    else
    begin
        product = product >> 1; // shift to the right
    end
end

endmodule 
verilog quartus
1个回答
0
投票

你的语法错误的原因是你不能只写:

product [7:4] = 4'b0000;

你必须写

assign product [7:4] = 4'b0000;

但是,除非您使用的是 System-Verilog(而您的老式编码风格表明您不是),否则您会发现

assign product [7:4] = 4'b0000;

也不会编译,因为

assign
语句的目标必须是
wire
,而不是
reg
。如果您将
product
更改为
wire
,您会发现这些语句会给您带来错误:

product = product >> 1; // shift right, and assign the most significant bit to 0
product[7:3] = product[7:3] + multiplicand[4:0]; // add 5-bits so we can handle the carry-out

product = product >> 1; // shift to the right

因为您不能分配给

wire
(或
always
)块中的
initial

您似乎正在设计某种移位加法乘法器,并且大概想在计算开始时初始化

product
。 (假设您对语法进行排序)行

(assign) product [7:4] = 4'b0000;
(assign) product [3:0] = multiplier [3:0];

一直持续驾驶

product
;他们没有初始化
product
。你在这里设计硬件,而不是编写软件。

© www.soinside.com 2019 - 2024. All rights reserved.