2

When I initialize an array sbox, I am getting syntax errors. Please help me out.

  reg  [7:0] sbox[15:0];
sbox = '{
 8'h63, 8'h7c, 8'h77, 8'h7b,
 8'hf2, 8'h6b, 8'h6f, 8'hc5,
 8'h30, 8'h01, 8'h67, 8'h2b,
 8'hfe, 8'hd7, 8'hab, 8'h76
};

This is actually sbox. Error it was showing:

near "=": syntax error, unexpected '=', expecting IDENTIFIER or TYPE_IDENTIFIER

I was using modelsim simulator

0

2 Answers 2

6

The syntax you are using for the array assignment is only valid in SystemVerilog, not Verilog.

So your compiler needs to support this, and you need to tell the compiler that the file is SystemVerilog. Most compilers (including modelsim) will assume the file type based on the extension, e.g. .v == Verilog and .sv == SystemVerilog, while others required a switch.

In addition, as pointed out in the answer from toolic, you need to place the assignment in an initial block, or you could combine the declaration with the assignment, like this:

reg [7:0] sbox[15:0] = '{
        8'h63, 8'h7c, 8'h77, 8'h7b,
        8'hf2, 8'h6b, 8'h6f, 8'hc5,
        8'h30, 8'h01, 8'h67, 8'h2b,
        8'hfe, 8'hd7, 8'hab, 8'h76
};
Sign up to request clarification or add additional context in comments.

Comments

0

The assignment should be inside an initial or always block:

module tb;

reg [7:0] sbox[15:0];

initial begin
    sbox = '{
        8'h63, 8'h7c, 8'h77, 8'h7b,
        8'hf2, 8'h6b, 8'h6f, 8'hc5,
        8'h30, 8'h01, 8'h67, 8'h2b,
        8'hfe, 8'hd7, 8'hab, 8'h76
    };
end

endmodule

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.