Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

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
 

echo47

Advanced Member level 5
Joined
Apr 7, 2002
Messages
3,942
Helped
636
Reputation
1,270
Reaction score
88
Trophy points
1,328
Location
USA
Activity points
33,183
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
 

sqwang93

Newbie level 2
Joined
Jan 5, 2006
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,296
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];
 

mona_c

Junior Member level 1
Joined
Jan 1, 2006
Messages
18
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,476
Re: a simple question

Walaikum Assalaam Usman ji

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


khush raho
feAmaanAllah
 

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
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.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top