how many bits can be stored in each address in a ram?

Thread Starter

Werapon Pat

Joined Jan 14, 2018
35
Adress : Data
0000 xxxxxxxx
0001 xxxxxxxx
0002 xxxxxxxx
0003 xxxxxxxx

Suppose this is my own ram which has only 1-byte for each address. if I declare an integer variable which requires 2-byte, it will allocate the memory
from adress 0000-0001 , but I wonder for the computer that we use in nowadays, how many bits can be stored in each address in a ram?
Does it depend on OS-system? like 32-bits or 64-bits or depend on my ram like what kind of ram that I used like DDR4 DDR3 (I don't really know what that means) and I wonder how is the data in the variable represented.
suppose I declare variables x = 4
then does it go like this
Adress : 0000 0001
data: 00000000 00000100
or
Adress : 0001 0000
data: 00000000 00000100
 
Last edited:

xox

Joined Sep 8, 2017
936
Each address in RAM is usually byte-addressable (so 8-bits "per address"). The 64-bit/32-bit designations signify the maximum address that can accessed by the CPU and also the maximum "word-size" for integer instructions. How allocations are actually decided is a bit arbitrary (from the programmer's perspective) but unsurprisingly the lowest address is (AFAIK) always returned from allocation routines. That said things like the stack generally are designed to grow backwards, but that wasn't really part of of your question, just a sidenote.
 

nsaspook

Joined Aug 27, 2009
16,377
How many bits are allocated vs how many bits are used by the variable depends on the word size, byte addressing capabilities of the processor, system variable size O/S API and programming language of the processing system. For large scientific systems byte-addressing is usually not very important so each address was usually word sized. With character bases systems dominating having byte sized address becomes more important for programming efficiency.
 

xox

Joined Sep 8, 2017
936
How many bits are allocated vs how many bits are used by the variable depends on the word size, byte addressing capabilities of the processor, system variable size O/S API and programming language of the processing system. For large scientific systems byte-addressing is usually not very important so each address was usually word sized. With character bases systems dominating having byte sized address becomes more important for programming efficiency.
Good point, another thing is that systems will sometimes place restrictions on how "words" are aligned, like 32-bit aligned to a 4-byte boundary, 64-bit to 8-byte boundaries, etc.
 

WBahn

Joined Mar 31, 2012
33,011
Each address in RAM is usually byte-addressable (so 8-bits "per address"). The 64-bit/32-bit designations signify the maximum address that can accessed by the CPU and also the maximum "word-size" for integer instructions. How allocations are actually decided is a bit arbitrary (from the programmer's perspective) but unsurprisingly the lowest address is (AFAIK) always returned from allocation routines. That said things like the stack generally are designed to grow backwards, but that wasn't really part of of your question, just a sidenote.
The "bit designation" is usually the internal register width as seen by the user (which is seldom the same as the actual internal register width, which is usually quite a bit wider -- for instance, the internal register width of most Intel-compatible processors is 80 bits to be able to accommodate their internal floating point representation). It has very little to do with the amount of memory that can be addressed by the CPU. For instance, for a long time PCs used 16-bit processors, which if this claim were true would only be able to access 65,536 words of memory. Yet even the 8088 could address 1 MB of memory. In that case, it had an internal 16-bit data path but the external data path was only 8-bits while the address buss what 20 bits. So the fact that it was a 16-bit processor told you nothing about either how much memory it could address or how many bits were stored at each address. Today's 64-bit processors cannot come anywhere close to being able to access 2^64 bytes of RAM since, as far as I know, the widest memory buses that any of them have today is 52 bits but very few have more than 48 (which is enough to access 128 TB of RAM).
 
Adress : Data
0000 xxxxxxxx
0001 xxxxxxxx
0002 xxxxxxxx
0003 xxxxxxxx

Suppose this is my own ram which has only 1-byte for each address. if I declare an integer variable which requires 2-byte, it will allocate the memory
from adress 0000-0001 , but I wonder for the computer that we use in nowadays, how many bits can be stored in each address in a ram?
Does it depend on OS-system? like 32-bits or 64-bits or depend on my ram like what kind of ram that I used like DDR4 DDR3 (I don't really know what that means) and I wonder how is the data in the variable represented.
suppose I declare variables x = 4
then does it go like this
Adress : 0000 0001
data: 00000000 00000100
or
Adress : 0001 0000
data: 00000000 00000100
Regarding the last part of question, It is called ... Little Endian vs Big Endian
for example, a 16 bit variable like: int x = 4 then ...

Generally for Intel CPU's, they are Little Endian ( Low Byte first ) as follows ...
0000 = 0000 0100 <<< Low Byte
0001 = 0000 0000 <<< High Byte
0002 = xxxx xxxx
0003 = xxxx xxxx

Generally for Motorola CPU's, they are Big Endian ( High Byte first ) as follows ...
0000 = 0000 0000 <<< High Byte
0001 = 0000 0100 <<< Low Byte
0002 = xxxx xxxx
0003 = xxxx xxxx
 
Top