So, the problem is that I needed to initialize an array of 32 bit words with a byte pattern inside a loop with a really badly dimensioned looping variable (not my code). Because it was a quick hack, I didn't want to restructure the loop, just to try the test code. So, the working solution was to do the following:
reg [15:0] index;
reg [31:0] data_word;
for (index = 0 ; index < buflen ; index = index+1) begin
data_dword = (((index*4+'h13)&8'hFF) << 24) | (((index*4+'h14)&8'hFF) << 16) | (((index*4+'h15)&8'hFF) << 8) | (((index*4+'h16)&8'hFF) << 0);
//I expect to get something like 32'h13141516, 32'h1718191a
end
I thought that I could maybe use a concatenation operator:
data_dword = {((index*4+'h13)&8'hFF), ((index*4+'h14)&8'hFF), ((index*4+'h15)&8'hFF), ((index*4+'h16)&8'hFF)};
But this doesn't work properly. I get 32'h00000016, 32'h0000001a, etc. i.e. only last byte available, all others are overwritten. Why so? I suppose that the length of each sub-expression:
((index*4+'h13)&8'hFF)
is not properly adjusted (is 32 bit for some reason), so the overall concatenation becomes truncated.