Assalam o Alaikum to All!!!
i am confused in a very simple question....plz u people clear/solve it..
if i want the value of a single bit of memory , how can i....
i.e reg [7:0] mem [0:1023];
now i want to access bit no 4 of location no 512 of memory....
and can i apply a loop on it to access memory bit wise...
regards,
Muhammad Usman
Here's a module that initializes the array with random bits, and then uses two counters to read them out:
Code:
module top (clk, out);
input clk;
reg [7:0] mem [0:1023];
reg [9:0] addr = 0;
reg [2:0] bit = 0;
output reg out;
integer x, y;
initial begin
for (y=0; y<1024; y=y+1)
for (x=0; x<8; x=x+1)
mem[y][x] = $random;
end
always @ (posedge clk) begin
bit <= bit + 1;
addr <= addr + &bit;
out <= mem[addr][bit]; // some synthesis tools can't swallow this
end
endmodule