Skip to main content
\(\newcommand{\doubler}[1]{2#1} \newcommand{\binary}{\texttt} \newcommand{\hex}{\texttt} \newcommand{\octal}{\texttt} \newcommand{\prog}{\texttt} \newcommand{\lt}{ < } \newcommand{\gt}{ > } \newcommand{\amp}{ & } \)


We now have the language necessary to begin discussing the major components of a computer. We start with the memory.

You can think of memory as a (very long) array of bytes. Each byte has a particular location (or address) within this array. That is, you could think of


as specifying the \(124^{th}\) byte in memory. (Don't forget that array indexing starts with 0.) Each byte in memory is numbered. We generally do not use array notation and simply use the index number, calling it the address or location of the byte.

The address of a particular byte never changes. That is, the \(957^{th}\) byte from the beginning of memory will always remain the \(957^{th}\) byte. However, the state of each of the bits—either \(\binary{0}\) or \(\binary{1}\)—in any given byte can be changed.

Computer scientists typically express the address of each byte in memory in hexadecimal. So we would say that the \(957^{th}\) byte is at address 0x3bc.

From the discussion of hexadecimal in Section 2.1 we can see that the first sixteen bytes in memory have the addresses \(\binary{0}\text{,}\) \(\binary{1}\text{,}\) \(\binary{2}\text{,}\) \(\binary{3}\text{,}\) \(\binary{4}\text{,}\) \(\binary{5}\text{,}\) \(\binary{6}\text{,}\) \(\binary{7}\text{,}\) \(\binary{8}\text{,}\) \(\binary{9}\text{,}\) \(\binary{a}\text{,}\) \(\binary{b}\text{,}\) \(\binary{c}\text{,}\) \(\binary{d}\text{,}\) \(\binary{e}\text{,}\) and \(\binary{f}\text{.}\) Using the notation

address: contents (bit pattern at the address)

we could show the (possible) contents (the state of the bits) of each of the first sixteen bytes of memory as in Table 2.4.1. Pay particular attention to the fact that two hexadecimal characters exactly specify the state of each of the eight bits in a byte.

\(\hex{00000000}:\) \(\hex{6a}\)      \(\hex{00000008}:\) \(\hex{f0}\)
\(\hex{00000001}:\) \(\hex{f0}\)      \(\hex{00000009}:\) \(\hex{02}\)
\(\hex{00000002}:\) \(\hex{5e}\)      \(\hex{0000000a}:\) \(\hex{33}\)
\(\hex{00000003}:\) \(\hex{00}\)      \(\hex{0000000b}:\) \(\hex{3c}\)
\(\hex{00000004}:\) \(\hex{ff}\)      \(\hex{0000000c}:\) \(\hex{c3}\)
\(\hex{00000005}:\) \(\hex{51}\)      \(\hex{0000000d}:\) \(\hex{3c}\)
\(\hex{00000006}:\) \(\hex{cf}\)      \(\hex{0000000e}:\) \(\hex{55}\)
\(\hex{00000007}:\) \(\hex{18}\)      \(\hex{0000000f}:\) \(\hex{aa}\)
Table2.4.1Possible contents of the first sixteen bytes of memory. Note that the addresses are shown as 32-bit values. (The contents shown here are arbitrary.)

Once a bit (switch) in memory is set to either zero or one, it stays in that state until the control unit actively changes it or the power is turned off. You have probably heard the term RAM used for such memory, which stands for Random Access Memory. The control unit can both read the state of each bit and change it. The terminology used here is inconsistent. “Random access” means that it takes the same amount of time to access any byte in the memory, not that there is randomness involved. This is in contrast to memory that is sequentially accessible, e.g., tape, where the length of time it takes to access a byte depends upon the physical location of the byte with respect to the current position of the tape.

Computers also contain Read Only Memory or ROM, in which the bits are permanently set. Such memory is called . The control unit can read the state of each bit but cannot change it.

A bit can be used to store data. For example, we could use a single bit to indicate whether a student passes a course or not. We might use \(\binary{0}\) for “not passed” and \(\binary{1}\) for “passed.” A single bit allows only two possible values of a data item. We cannot for example, use a single bit to store a course letter grade—A, B, C, D, or F.

How many bits would we need to store a letter grade? Consider all possible combinations of two bits:


Since there are only four possible bit combinations, we cannot represent all five letter grades with only two bits.

Let us add another bit and look at all possible bit combinations:


With eight possible bit combinations, we have more than enough bits to store any of the letter grades. For example, we could use the code:

Letter Grade Bit Pattern
A \(\binary{000}\)
B \(\binary{001}\)
C \(\binary{010}\)
D \(\binary{011}\)
F \(\binary{100}\)

This example illustrates two issues that a programmer must consider when storing data in memory in addition to its location(s):

  1. How many bits are required to store the data? In order to answer this we need to know how many different values are allowed for the particular data item. Study the two examples above—two bits and three bits—and you can see that adding a bit doubles the number of possible values. Also, notice that we might not use all the possible bit patterns within an allocated space.

  2. What is the code for storing the data? Most of the data we deal with in everyday life is not expressed in terms of zeros and ones. In order to store it in computer memory, the programmer must decide upon a code of zeros and ones to use. In the above (three bit) example we used \(\binary{000}\) to represent a letter grade of ‘A’, \(\binary{001}\) to represent ‘B’, etc.

For example, in our grade grade example, a programmer may choose to store the letter grade at byte number \(\hex{befff64a}\) in memory. If the grade is ‘A’, the programmer would set the bit pattern at location \(\hex{befff64a}\) to \(\hex{00}_{16}\text{,}\) if the grade is ‘C’, the programmer would set the bit pattern to \(\hex{02}_{16}\text{,}\) etc. In this example, one of the jobs of an assembly language programmer would be to determine how to set the bit pattern at byte number \(\hex{befff64a}\) to the appropriate value.

High-level languages use data types to determine the number of bits and the storage code. For example, in C you may choose to store the letter grades in the above example in a char variable and use the characters ‘A’, ‘B’,…,‘F’ to indicate the grade. In Section 2.7 you will learn that the compiler would use the following storage formats:

Letter Grade Bit Pattern
A \(\hex{41}\)
B \(\hex{42}\)
C \(\hex{43}\)
D \(\hex{44}\)
F \(\hex{46}\)

And programming languages, even assembly language, allow programmers to create symbolic names for memory addresses. The compiler (or assembler) determines the correspondence between the programmer's symbolic name and the numerical address. The programmer can refer to the address by simply using the symbolic name.



Say you want to allocate an area in memory for storing any number in the range \(0\)—\(4,000,000,000\text{.}\) This memory area will start at location \(\hex{0x2fffeb96}\text{.}\) Give the addresses of each byte of memory that will be required.

Hint Answer

You need to allocate an area in memory for storing an array of 30 bytes. The first byte will have the value \(0\) stored in it, the second \(1\text{,}\) the third \(2\text{,}\) etc. This memory area will start at location \(\hex{0x00100e}\text{.}\) Show what this area of memory looks like.


We have shown how to write only the first sixteen addresses in hexadecimal in Figure 2.4.1. How would you write the address of the seventeenth byte (byte number sixteen) in hexadecimal?

Hint Answer