Electronic – How big variables are stored in RAM memory

memoryram

I've just made a simple RAM memory in Minecraft (with redstone), with 4 bits for the address and 4 bits stored in each cell. Our next goal is to store different kinds of variables in it and to process them differently.

We are not engineers, so we really know nothing, but we have already made some quite complex things and we think we can do this. The problem is that we can't figure out how to store variables of more bits than can be stored in a single cell. I'll give an example.

Think of a 16-bit variable. We thought that there would be no sense in creating such big cells, so we decided to store that data by storing 4 bits in each cell. But that's not enough, we have to relate those 4 cells to each other. So we thought that we had to create 8-bit cells, with 4 bits of content and 4 bits to store the address where the next 4 bits of the variable are stored. However, 4 bits of address is nothing for a RAM memory, we can't store anything there. So we would need at least 8 bits for the address. 4 bits of content also seams quite low, and we also need at least another 4 bits to store the type of the variable.

Well, finally we thought that that technique was absurd and that it wouldn't be done like that in real life. And we don't know how to do it now. I've searched on the web about how RAM memory works and the few pages that I've found were too complex for our needs. Could someone please explain to us how this is done in real life and how we can apply it in redstone?

Best Answer

It's not clear what you are really asking, but it is common to store binary values that are wider than the addressable unit of memory. For example, if you want to store 16 bit words in a byte-addressed memory, then you use two bytes. That also means the software has to know which byte is stored first.

In your case you seem to have native 4 bit words. To store a 16 bit value, use 4 words. Again, your software will have to know what convention you are using, like low word first or high word first.

Since your memory only has 4 address lines, its size is limited to 16 native words. Your native word size appears to be 4 bits, so your memory can hold only 64 bits. That means it will be completely used up by two 32 bit values or four 16 bit values, for example.