Search code examples
veriloghdl

Verilog HDL error: Illegal left-hand side assignment


I am learning CPU Design and basic Verilog HDL. I have a processor running in tkgate on Fedora 29 and I have designed a hardware RAM disk. I can't test the RAM but have decided to replace it with an HDL RAM disk. Whenever I try to simulate the circuit, I get the error:
RAM_HDL, line 17: Illegal use of 'w7' in left-hand-side assignment.
Here is my code for the 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:

Data_Out <= Address;  

Solution

  • 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