Navigation links:

Introduction to Computer Memory

Since computers represent everything as numbers, computer memory only has to be able to store and retrive numbers. This section is only going to discuss primary computer memory; secondary computer memory is discussed in another chapter.

Memory Cells

Primary computer memory, is made up of memory cells, where each memory cell contains exactly one number. Thus, a memory cell can be thought of as box into which a single number can be placed. The number contained in a memory cell can be changed over time. When a new number is stored into a memory cell, the old number contained in the memory cell is lost forever. At any time, the computer may peer into a memory cell to read the current contents of the memory cell. The computer may read the contents of a memory cell as many times as it wants, without disturbing it.

A typical computer has millions of memory cells, and every memory cell has a name. While a small number of memory cells are given specialized names, such as `Program Counter' or `Processor Status Register', most memory cells are named using a unique number. (Remember, from the previous chapter, everything in a computer is a number!) The unique number that names a memory cell is called its `address.' No two memory cells have the same address. The address of a memory cell never changes over time. Going back to the box analogy of the previous paragraph, the address of a memory cell can be thought of as a number permanently imprinted on the side of the box in indelible ink. Thus, every memory cell has two numbers -- its address (which never changes) and its current contents (which changes over time.)

Since a memory cell has both a contents and an address, both of which are numbers, it is useful to adopt a notation to keep them separate. A fairly common notation is to enclose the memory cell address in square brackets, followed by a colon, followed by the memory cell contents. For example, `[223]: 17' is the notation used to specify that memory cell [223] currently has the number 17 as its contents.

As an example, consider the two arbitrary memory cells named [223] and [873]. When power is first applied to these two memory cells, both cells will have an initial contents of zero; this is shown below:

	[223]: 0		[873]: 0
								
Eventually, the computer comes along and writes the number 104 into memory cell [223]; this is shown below:
	[223]: 104		[873]: 0
								
Later on, the computer writes the number 105 into memory cell [873]; this is shown below:
	[223]: 104		[873]: 105
								
Even later on, the computer overwrites memory cell [223] with 72. The previous contents of memory cell [223] is lost forever; this is shown below:
	[223]: 72		[873]: 105
								
Finally, at some even later point in time, the number 104 is stored back into memory cell [223]. Again, the previous contents of memory cell [223] is lost forever; this is shown below:
	[223]: 104		[873]: 105
								
The computer reads and overwrites the contents of memory cells [223] and [873] as many times as needed to accomplish its current task.

Memory Arrays

Since every memory cell named with a unique address number, they are named using sequential numbers starting from the number zero. Thus, the first memory cell has an address number of [0], the second memory cell has an address number of [1], and so forth until all memory cells have been given an address number. The memory cells can be listed vertically down the page as follows:
	[0]: 0
	[1]: 0
	[2]: 0
	[3]: 0
	[4]: 0
	[5]: 0
	[6]: 0
	[7]: 0
	[8]: 0
	[9]: 0
	[10]: 0
	[11]: 0
	[12]: 0
								
The thirteen memory cells above have addresses from [0] to [12]. All thirteen memory memory cells contain the number 0.

While memory can easily be listed veritcally as shown above, it is not very compact. A more compact representation is to list the memory cells as an array. An example memory array is shown below and the paragraph describing it follows:

+----+-----------------------------------------------------------+
|1st |                        Last Digit			 |
|Dig.|  0     1     2     3     4     5     6     7     8     9  |
|----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
|  0 |    0|    0|    0|    0|    0|    0|    0|    0|    0|    0|
|    +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
|  1 |    0|    0|    0|    0|    0|    0|    0|    0|    0|    0|
|    +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
|  2 |    0|    0|    0|    0|    0|    0|    0|    0|    0|    0|
|    +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
|  3 |    0|    0|    0|    0|    0|    0|    0|    0|    0|    0|
|    +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
|  4 |    0|    0|    0|    0|    0|    0|    0|    0|    0|    0|
|    +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
|  5 |    0|    0|    0|    0|    0|    0|    0|    0|    0|    0|
|    +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
|  6 |    0|    0|    0|    0|    0|    0|    0|    0|    0|    0|
|    +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
|  7 |    0|    0|    0|    0|    0|    0|    0|    0|    0|    0|
|    +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
|  8 |    0|    0|    0|    0|    0|    0|    0|    0|    0|    0|
|    +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
|  9 |    0|    0|    0|    0|    0|    0|    0|    0|    0|    0|
|    +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
| 10 |    0|    0|    0|    0|    0|    0|    0|    0|    0|    0|
|    +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
| 11 |    0|    0|    0|    0|    0|    0|    0|    0|    0|    0|
|    +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
| 12 |    0|    0|    0|    0|    0|    0|    0|    0|    0|    0|
|    +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
|... |                            ...				 |
								
This array is very similar to the ASCII character set array shown in the previous chapter. Each row lists the contents of ten consecutive memory cells. Thus, the first row lists the contents of the ten memory cells whose addresses are [0] through [9], the second row lists the contents of the ten memory cells whose addresses are [10] through [19], etc. For the memory array above, every memory cell has a contents of zero.

An even more compact representation is possible by dropping all of the lines between rows and columns and dropping all of the column headings. An example of the more compact representation is shown below:

[0x]:     0     0     0     0     0     0     0     0     0     0
[1x]:     0     0     0     0     0     0     0     0     0     0
[2x]:     0     0     0     0     0     0     0     0     0     0
[3x]:     0     0     0     0     0     0     0     0     0     0
								
The small `x' in [0x], [1x], [2x], and [3x] is a place holder for the last digit of the memory cell address. Thus, memory cell [20] corresponds to the first number after the colon on the row labeled [2x], memory cell [21] corresponds to the second number, and so forth. The last number on the row labeled [2x] corresponds to the [29] memory cell.

As an example of memory use, let's store each character of the word `Hello!' into consecutive memory cells starting at memory cell [22]. The conversion for each character can be looked up in the ASCII character set table shown in the previous chapter. For convenience, the conversions are listed below:

After the computer has stored the word `Hello!' into memory, the memory looks as follows:
[0x]:     0     0     0     0     0     0     0     0     0     0
[1x]:     0     0     0     0     0     0     0     0     0     0
[2x]:     0     0    74   101   108   108   111    33     0     0
[3x]:     0     0     0     0     0     0     0     0     0     0
								
The word `Hello!' can be changed into `Help!!' by overwriting memory cells [25] and [26] with the numbers corresponding to the letters `p' (112) and `!' (33). The resulting memory looks as follows:
[0x]:     0     0     0     0     0     0     0     0     0     0
[1x]:     0     0     0     0     0     0     0     0     0     0
[2x]:     0     0    74   101   108   112    33    33     0     0
[3x]:     0     0     0     0     0     0     0     0     0     0
								
To finish off the example, the word `Help!!' can be changed into `Bye!!!' by overwriting memory cells [22] through [25] with the numbers corresponding to the letters `B' (68), `y' (121), `e' (101), and `!' (33). The resulting memory looks as follows:
[0x]:     0     0     0     0     0     0     0     0     0     0
[1x]:     0     0     0     0     0     0     0     0     0     0
[2x]:     0     0    68   121   101    33    33    33     0     0
[3x]:     0     0     0     0     0     0     0     0     0     0
								

Memory Limitations

It turns out that memory cells have a restriction on how big of a number they can store. While historically the number size limitations have varied from computer to computer, most current computers use a memory cell whose contents is limited to a number between 0 and 255. It is not important what the exact memory cell limit is; what is important is that you understand that large numbers do not fit in a single cell. When a number is too large to fit in a single cell, it is stored in a number of consecutive memory cells.

For the memory used in this and subsequent chapters, the memory cells are limited to positive and negative numbers of five digits or less (i.e. -99999 to 99999.) This choice will make it easy to see how large numbers are spread across multiple memory cells.

Big Numbers

For the memory in this chapter, if a number is larger than five digits, it is broken into a sequence of smaller five digit numbers and stored in consecutive memory cells. For example, the nine digit number 123456789 is stored as the number 1234 in one cell and as 56789 in the next cell. This is shown as follows:
[22]:  1234
[23]: 56789
								
Even larger numbers (like the U.S. national debt), take even more consecutive memory cells.

For the example above, the most significant digits are stored in the first memory cell, followed by the least significant digits. It turns out that this is just a convention. The computer can just as easily store the least significant digits first, as shown below:

[22]: 56789
[23]:  1234
								
As long as the numbers are stored consistently, no problems ensue.

It turns out that some computers store big numbers with the most significant digits first and others store big numbers with the least significant digits first; the former computers are called `big-endian' and the latter computers are called `little-endian'. The terms big-endian and little-endian are a reference to the Lilliputians in the book Gulliver's Travels written by Johnathan Swift. In Gulliver's Travels, the war between the Lilliputians was over whether hard boiled eggs should be eaten from the big end of the egg first or the little end of the egg first. Obviously, it is pretty silly to have a war over which end of a hard boiled egg to eat first. Likewise, as long as a computer is consistent, it does not matter whether it is big-endian or little endian. Sometimes computer scientists will get into arguments whether big-endian or little-endian representations are better; such arguments are ultimately pretty silly and should be ignored. When a number is transmitted between a little-endian computer and a big-endian computer, one of the computers will have to reverse the sequence of smaller numbers prior to further processing.

A Quick Summary

In this chapter you should have learned:

The next chapter introduces the topic of low-level computer programming.

Wayne C. Gramlich

Copyright 1993 (c) Wayne C. Gramlich. All Rights Reserved.

Limited copy permission is granted. Comments, corrections, and cross references are solicited. There are currently no known cross references.