我正在编写一个代码来移动 128 位寄存器 25 位置,然后将它的前 96 位存储在 RAM 中(RAM 中的 mem_bank 宽度 = 16 位),我尝试清除计数器以在第一个时钟周期进行移位并存储子值在接下来的 6 (96/16) 个周期中,在 RAM 中。我使用计数器进行索引,但我有一个问题,即计数器不是恒定的???这是RAM的代码
module RAM(clk,we,din,dout,address);
input clk,we,re;
input [15:0] din;
input [5:0] address;
output [15:0] dout;
reg [15:0] dout;
reg [15:0] mem_bank [0:51];
integer i;
initial
begin
for (i=0;i<52;i=i+1)
mem_bank[i] <=0;
end
always @(posedge clk)
begin
if(we)
mem_bank[address] <= din;
dout <= mem_bank[address];
end
endmodule
这是移位寄存器的代码
module keygen(clk,load,data0,data1,data2,data3,out1,out0);
input clk,load;
input [31:0] data0,data1,data2,data3;
output [31:0] out1,out0;
reg [127:0] reg128;
integer adrs = 0; //address of RAM from 0 to 51
integer count=0;
parameter KEYSIZE = 16;
integer lowindex=0;
integer highindex=0;
always @(posedge clk)
begin
if(load)
reg128 <= {data3,data2,data1,data0};
else if(count < 1)
begin
reg128 [127:25] <= reg128 [102:0];
reg128 [24:0] <= reg128 [127:103];
count =count + 1;
end
else if(count <8 && adrs < 52)
begin
// lowindex= (count-2)*KEYSIZE;
// highindex = (count-2)*KEYSIZE+KEYSIZE-1;
RAM ram(.clk(clk),.we(1),.din(reg128[(count-2)*KEYSIZE:(count-2)*KEYSIZE+KEYSIZE-1]),.address(adrs));
adrs=adrs+1;
if (count < 8)
count =count + 1;
else
count = 0;
end
end
assign out0=reg128[31:0];
assign out1=reg128[63:32];
//assign out2=reg128[95:64];
//assign out3=reg128[127:96];
endmodule
任何帮助请解决这个问题