I am trying to implement a 16byte input (K) in Verilog which I have never done before. Also, I need to pull each byte from the index K using a for loop. In this case, b=16bytes, w=32bits, u=w/8. Here is the for loop pseudo code I took from the RC5 encryption paper:
for i = b - 1 downto 0 do:
L[i/u]=(L[i/u]<<8)+K[i];
Here is my attempt in Verilog. I am also having trouble telling the for loop to decrease from 15 down to 0 in steps of 1.
module RC6_KeyScheduler( in, clk, out );
input byte [0:7] K[0:15] ; // Input should be 16bytes
input clk;
output reg [0:127] out;
parameter b = 16;
parameter w = 32; // word length in bits
parameter u = w/8;
parameter c = 4;
integer i;
reg [0:31] L[0: c-1];
//<statements>
always@ (*)
for (i = b-1, i>-1; i=i-1)
begin
L[i/u] = (L[i/u] << 8) + K[i];
end
endmodule
Right now I am getting errors on the way I am defining my input K and on my inequality in my for loop.
Any comments on how to fix my Verilog code to match the pseudocode would be appreciated.
1 Answer 1
I got this helpful error when I tried to compile the code on the VCS simulator:
input byte [0:7] K[0:15] ; // Input should be 16bytes
Error-[SV-PDNA] Packed dimensions not allowed
Packed dimensions not allowed on type 'byte'.
Packed dimensions are only allowed on types resolving to single bit types
(reg, logic or bit), packed arrays, packed structures, and packed unions.
You should either drop the byte
keyword (which declares an 8-bit type) or [0:7]
.
I got another error because your port list did not match your port declarations because K
is missing from the list. You can simplify this by using ANSI style declarations which I will show below. There is no need to maintain 2 lists.
I got another error on your for
statement: you need a semicolon instead of a comma.
Putting this all together, the following code compiles without errors for me:
module RC6_KeyScheduler (
input [0:7] K [0:15] , // Input should be 16bytes
input in, clk,
output reg [0:127] out
);
parameter b = 16;
parameter w = 32; // word length in bits
parameter u = w/8;
parameter c = 4;
integer i;
reg [0:31] L[0: c-1];
always @(*)
for (i = b-1; i>-1; i=i-1)
begin
L[i/u] = (L[i/u] << 8) + K[i];
end
endmodule
Perhaps the simulator you are using does not give you errors for all these cases. Or, perhaps the error messages are not clear enough. You can sign up for a free account at edaplayground, where you will have access to multiple simulators. Sometimes you can get more helpful error messages with different simulators.
Explore related questions
See similar questions with these tags.
[0:7]
after thebyte
? And doesn'ti
need to be agenvar
? \$\endgroup\$parameter c = b/u ;
,reg [0 : w-1] L [0 : c-1] ;
,input [0 : 7] K [0 : b-1] ;
\$\endgroup\$