Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to get the value of a single bit in a memory?

Status
Not open for further replies.

usman

Junior Member level 3
Joined
Aug 4, 2005
Messages
27
Helped
2
Reputation
4
Reaction score
0
Trophy points
1,281
Activity points
1,502
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
 

Re: a simple question

I assume you are talking about Verilog.

To access bit 4 of address 512, use mem[512][4]

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
 

Re: a simple question

I assume you use Verilog.

To access bit 4 of address 512:

reg [7:0] tmp_reg;
reg bit_4;

tmp_reg <= mem[512];

bit_4 <= tmp_reg[4];
 

Re: a simple question

Walaikum Assalaam Usman ji

Hope u got the ans ..if not yet then ..tell us


khush raho
feAmaanAllah
 

Re: a simple question

Assalam o Alaikum!! mona Jii!!!
really my problem was solved by echo47 & sqwang>>>thank you very much

Muhammamd Usman
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top