1
    input [31:0] write_data;
    input [4:0]  write_reg;
    reg [31:0] registers [31:0];

always @(*) 
     assign registers[write_reg] = write_data;

I have a 32-bit input write_data , which i want to an assign corresponding index which i get from write reg.Error says you cant do continuous assignment which i think causes by always@(*) but if i remove that

It says object "registers" on left-hand side of assignment must have a net type and its another error.

stacknotflow
  • 15
  • 1
  • 1
  • 3
  • Possible duplicate of [Error "procedural assignment to a non-register result is not permitted"](https://stackoverflow.com/questions/31472546/error-procedural-assignment-to-a-non-register-result-is-not-permitted) – Qiu Nov 17 '17 at 13:23

2 Answers2

4

assign inside an always block is the procedural assignment. It is not synthesizable and should not be used. It is there for very special modeling cases.

continuous assignment, or assign outside the always block is there for connecting nets and used all over the places. lhs of such an assignment must be a net type, i.e. wire. it cannot be a reg.

On the other hand all lhs in always blocks must be of 'reg' type.

what you had to do in your case was to remove the keyword assign:

input [31:0] write_data;
input [4:0]  write_reg;
reg [31:0] registers [31:0];

always @(*) 
     registers[write_reg] = write_data;
Serge
  • 11,616
  • 3
  • 18
  • 28
  • What is a practical use-case for procedural assign statements? I swear I've never run into one myself. Feels like it should be deprecated on account of being an exceptionally attractive nuisance for beginners judging by how often the problem pops up here. – Brian Magnuson Nov 17 '17 at 17:58
  • @BrianMagnuson I am not really sure. I saw it only once in my practice used in gls simulation to work around some initialization problems. It was used incorrectly in any case and caused headache to debug the issues it itself introduced. I guess it could be used in some cells to model very specific electrical behavior. – Serge Nov 17 '17 at 18:30
0

You need to synchronously assign to registers. Because the synthesizer parses it and routes to a physical register (i.e. flip-flop)

always @(posedge clk) 
    my_reg = my_data;

A d-flip flop

Alper Kucukkomurler
  • 1,706
  • 2
  • 13
  • 19