[英]Verilog HDL error: Illegal left-hand side assignment
I am learning CPU Design and basic Verilog HDL. 我正在学习CPU设计和基本的Verilog HDL。 I have a processor running in tkgate on Fedora 29 and I have designed a hardware RAM disk.
我有一个在Fedora 29上的tkgate中运行的处理器,并且设计了一个硬件RAM磁盘。 I can't test the RAM but have decided to replace it with an HDL RAM disk.
我无法测试RAM,但已决定将其替换为HDL RAM磁盘。 Whenever I try to simulate the circuit, I get the error:
每当我尝试模拟电路时,都会出现错误:
RAM_HDL, line 17: Illegal use of 'w7' in left-hand-side assignment. RAM_HDL,第17行:在左侧分配中非法使用“ w7”。
Here is my code for the RAM: 这是我的RAM代码:
module RAM_HDL(RAM, Data_In, Data_Out, Address, RW);
reg [15:0] RAM [127:0];
wire [15:0] Data_In;
wire [15:0] Data_Out;
wire [7:0] Address;
wire RW;
initial
$readmemb("RAM_DATA.BIN", RAM);
always @(*)
begin
if (RW)
RAM[Address] <= Data_In;
Data_Out <= Address;
end
endmodule
The error is on line 17: 错误在第17行:
Data_Out <= Address;
I believe one of your problems is trying to assign to a wire type in an always block. 我相信您的问题之一就是试图在Always块中分配一种导线类型。 Try changing the declaration of Data_Out to reg instead of wire.
尝试将Data_Out的声明更改为reg而不是wire。 The 2 following examples compiled for me:
以下2个示例为我编译:
module RAM_HDL(Data_In, Data_Out, Address, RW);
reg [15:0] RAM [127:0];
input wire [15:0] Data_In;
output reg [15:0] Data_Out;
input wire [7:0] Address;
input wire RW;
initial
$readmemb("RAM_DATA.BIN", RAM);
always @(*)
begin
if (RW)
RAM[Address] <= Data_In;
Data_Out <= Address;
end
endmodule
note the changes. 注意更改。 input and output are declared on the ports.
输入和输出在端口上声明。 The ram array is not one of the ports and the data_out is a reg.
ram数组不是端口之一,而data_out是reg。
another option would be to move the assignment of data out outside the always block and keep it as a wire: 另一个选择是将数据分配移出Always块之外,并使其保持连线:
module RAM_HDL(Data_In, Data_Out, Address, RW);
reg [15:0] RAM [127:0];
input wire [15:0] Data_In;
output wire [15:0] Data_Out;
input wire [7:0] Address;
input wire RW;
initial
$readmemb("RAM_DATA.BIN", RAM);
always @(*)
begin
if (RW)
RAM[Address] <= Data_In;
end
assign Data_Out = Address;
endmodule
the changes are mostly the same. 变化基本相同。 the input output declarations and the ram array is removed from the port list.
输入输出声明和ram数组从端口列表中删除。 Data_Out however is now assigned outside the always block so it can stay a wire.
但是,现在将data_Out分配到Always块之外,这样它就可以保持连接。
The following code compiles at least: 以下代码至少可以编译:
module RAM_HDL(Data_In, Data_Out, Address, RW);
reg [15:0] RAM [127:0];
input [15:0] Data_In;
output [15:0] Data_Out;
input [7:0] Address;
input RW;
initial
$readmemb("RAM_DATA.BIN", RAM);
always @(*)
begin
if (RW)
RAM[Address] <= Data_In;
end
assign Data_Out = RAM[Address];
endmodule
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.