c02.qxd 7/20/2005 8:24 AM Page 23
2 COMPUTERS AND
It is unworthy of excellent men to lose hours,
like slaves, in the labors of calculation.
GOTTFRIED WILHELM LEIBNITZ (1646–1716)
Computers make it easier to do a lot of things,
but most of the things they make it easier to
do don’t need to be done.
ANDY ROONEY (1919–)
1 In this chapter we will learn about:
0 ● The brain of a computer
1 ● Memory devices
● Input and output ports
0 ● The control, data, and address busses
0 ● Using a computer to make a calculator
1 ● Our DIY Calculator
c02.qxd 7/20/2005 8:24 AM Page 24
24 COMPUTERS AND CALCULATORS
Rampaging Around a Computer
In its broadest sense, a computer is a device that can accept information
from the outside world, process that information using logical and/or
mathematical operations, make decisions based on the results of this
processing, and ultimately return the processed information to the out-
side world in its new form.
The main elements forming a computer system are its central pro-
cessing unit (CPU)—the memory devices (ROM and RAM) that are used
to store programs (sequences of instructions) and data—and the
input/output (I/O) ports that are used to communicate with the outside
world (Figure 2-1).
The “brain” of the computer is its CPU, which is where all of the
number crunching and decision making is performed. Two of the
CPU’s input pins are driven by externally generated signals called clock
and reset. The clock signal switches back and forth between two voltage
levels millions of times a second (or billions of times a second in the
case of today’s computers). In much the same way that the measured
beat of a drum can be used to keep a band marching in step, the
clock signal is used to synchronize the internal and external actions of
M Address bus
O u tp
p ut To the
U In outside world
Re From the
Cl o outside world
Figure 2-1. The main components forming a general-purpose digital computer.
c02.qxd 7/20/2005 8:24 AM Page 25
MEMORY DEVICES AND I/O PORTS 25
Sometimes, things may end up “pear-shaped” (an English expres-
sion for something that has taken an unfortunate turn of events, such as
a badly written program becoming locked up in an endless loop). In this
case, the reset signal can be used to force the CPU into a known, well-be-
haved state. (This signal is automatically activated when power is first
applied to the system, and the resulting power-on reset serves to initialize
Note Prior to the availability of ROM devices, computer users had to manually install the initialization in-
structions each time the computer was powered on. This was usually accomplished by setting a bank of switch-
es for each instruction and then pushing a button to input that instruction. This process, referred to as “boot-
ing up the computer,” could be long and tedious.
“Bootstraps” are small loops of leather sewn into the tops of high boots as an aid to pulling them on. Since the
18th century, the phrase “pulling oneself up by one’s own bootstraps” has meant “to succeed by one’s own ef-
forts.” Although “bootstrap” has been used in computing circles since the 1950s, the now-common shortened
form “boot” only became popular with the “personal computer explosion” of the 1980s.
Memory Devices and I/O Ports
With regard to the other components forming a computer system, the
ones in which we are interested here are the memory devices (each of
which may contain thousands or millions of pieces of data) and the in-
put and output ports. (In this context, the term “data” may be used to
encompass the raw data upon which programs operate along with the se-
quences of instructions forming the programs themselves.)
As their name might suggest, the data contained in read only memo-
ries (ROMs) is hard-coded during their construction. The CPU can read
(extract) data from ROM devices, but it cannot write (insert) new data
into them. Thus, ROMs may be used to store such things as the low-level
initialization and control routines that are required when the computer
is first powered up.
By comparison, data can be read out of random access memories
(RAMs) and new data can be written back into them (the act of reading
data from a RAM does not affect the master copy of the data stored in-
side the device). When power is first applied to the system, the RAMs
end up containing random values; this means that any meaningful data
stored inside a RAM must be written into it by the CPU (or via some
other mechanism) after the system has powered up. RAMs can be used to
store programs, data, and intermediate results.
c02.qxd 7/20/2005 8:24 AM Page 26
26 COMPUTERS AND CALCULATORS
Last but not least, the computer uses its input and output ports to
communicate with the outside world. (Figure 2-1 shows only individual
input and output ports, but a computer can effectively have as many of
each type as its designers wish to use.)
Note In addition to being somewhat esoteric, early attempts to create computer memories were typically
sequential in nature. By this we mean that it was only possible to retrieve data in the order in which it had been
stored (consider a magnetic tape, for example).
Thus, when it was invented, the term random access memory (RAM) was coined to emphasize the fact that this
new type of memory allowed data to be directly read from or written to any location in the device.
Some of us would prefer to use the more meaningful appellation read–write memory (RWM), but there is little
chance of this nomenclature becoming widely adopted.
The Control, Data, and Address Busses
As we previously noted, the term bus is used to refer to a group of signals
that carry similar information and perform a common function. A com-
puter actually makes use of three buses called the control bus, address bus,
and data bus. The CPU uses its address bus to “point” to other compo-
nents in the system, it uses the control bus to indicate whether it wishes
to “talk” (output/write/transmit data) or “listen” (input/read/receive
data), and it uses the data bus to convey information back and forth be-
tween itself and the other components. (To be honest, the clock and reset
signals are also considered to be part of the control bus, but these signals
are often treated separately as is illustrated in our diagrams.)
The data bus
For the purposes of these discussions, we’ll assume that we’re working
with a simple computer that has an 8-bit data bus. Note that the illustra-
tion shown in Figure 2-1 is rather abstract and makes the busses look like
solid entities. In reality, they are formed from groups of wires; for exam-
ple, let’s take a closer look at the data bus (Figure 2-2).
The address bus
Now try to visualize a series of thousands upon thousands of boxes
standing side-by-side and stretching away into the dim and distant be-
yond. Each box is numbered sequentially, commencing with zero
c02.qxd 7/20/2005 8:24 AM Page 27
THE CONTROL, DATA, AND ADDRESS BUSSES 27
To/from RAM To/from Rest
of System Individual
To Out Port
To/from CPU From In Port
(a) Abstract view (b) Less abstract view
Figure 2-2. The data bus.
Let’s imagine that some of these boxes have pieces of transparent
plastic sealing their ends, whereas the others are open to the elements.
Let’s further suppose that each of the sealed boxes contains a slip of pa-
per with a number written on it. We can read the numbers (data) on the
slips inside these boxes but we can’t alter them in any way. This is similar
to the way in which our ROM devices function.
In the case of an open box, we can write a number on a new slip of
paper and insert it into that box. If an open box already contains a slip of
paper, we might simply read the number on the slip but leave the slip
where it is, we might copy the slip and place the copy in another box, or
we might erase the number on the slip and write a new number in its
place. This is similar to the way in which our RAM devices operate.
Strange as it may seem, this is the way that the CPU views its
world—as a series of boxes that can be used to store instructions and
data (although we prefer to use the term memory locations rather than
“boxes”). Each location in the memory has a unique identification num-
0 1 2 3 4 5 6 7
Sealed boxes (ROM) Open boxes (RAM)
Figure 2-3. A series of boxes.
c02.qxd 7/20/2005 8:24 AM Page 28
28 COMPUTERS AND CALCULATORS
ber, referred to as its address, and the CPU uses its address bus to “point”
to any memory location in which it is currently interested (Figure 2-4).
Each location in the memory is referred to as a word, and each
word has the same width as the data bus. Thus, as our CPU’s data bus is
8 bits wide, each word in the memory must also be 8 bits wide. These bits
are numbered from 0 to 7, as shown in Figure 2-4 (the reason for this
numbering scheme is revealed in Chapter 4). Each bit in a memory word
can be used to store a 0 or a 1, and all of the bits forming a word are typi-
cally written to or read from simultaneously (the 0s and 1s shown in the
memory word at address $000A in Figure 2-4 have no meaning beyond
providing some example values).
The totality of memory locations that can be addressed by the
computer are referred to as its address space. In the case of our CPU,
we’re going to assume that the address bus is 16 bits (two bytes) wide.
This means that our address bus can carry 216 unique combinations of
0s and 1s, which can therefore be used to point to 65,536 different
memory locations numbered from 0 to 65,535. For a variety of reasons,
however, it is not convenient to refer to the addresses of memory loca-
tions using a decimal notation. Thus, rather than referring to a location
such as 48,259 using its decimal value (or worse, its binary equivalent
of %1011110010000011), it is common practice to refer to addresses
using a hexadecimal notation such as $BC83 (remember that we’re us-
ing the % and $ characters to indicate binary and hexadecimal values,
Data Bus $0000
Points to memory locations
(and I /O devices )
Cl o $0008
Memory word $0009
$000A 0 0 1 1 0 1 0 1 $000B
'$' characters indicate $000D
hexadecimal numbers. Bit 7 Bit 0 $000E
Figure 2-4. The address bus.
c02.qxd 7/20/2005 8:24 AM Page 29
CAREENING AROUND A CALCULATOR 29
Actually, we should note that the computer architecture we’re de-
scribing here reflects a very simple system that one might find in a low-
end application like a pocket calculator. This type of architecture was also
common in personal computers circa 1975. The busses and bus protocols
used in modern computers like PCs are much more sophisticated; but, as
was noted in Chapter 0, once you fully comprehend how a simple com-
puter functions, you can easily extrapolate to more complex machines.
Careening Around a Calculator
Once we’ve conceived the idea of a general-purpose computer, the next
step is to think of something to do with it. In fact, there are millions of
tasks to which computers can be assigned, but the application we’re in-
terested in here is that of a simple calculator. So what does it take to co-
erce a computer to adopt the role of a calculator? Well, one thing we re-
quire is some form of user interface, which will allow us to present data
to, and view results from, the computer (Figure 2-5).
The calculator’s user interface primarily consists of buttons and
some type of display. Each button has a unique binary code associated
with it, and this code will be presented to the computer’s input port
whenever that button is pressed. Meanwhile, one or more of the com-
RA Address bus
Ou l cu
r int e
In pu (bu
U t to
t CP ns
Figure 2-5. A calculator requires some form of user interface.
c02.qxd 7/20/2005 8:24 AM Page 30
30 COMPUTERS AND CALCULATORS
puter’s output ports can be used to drive the display portion(s) of the
So this interface is really a “dumb device,” because all of the actual
number crunching is performed by the general-purpose computer. How-
ever, in order for the computer to perform its cunning machinations, it
requires a program, and creating this program requires us to decide on
the ways in which we wish to represent and manipulate numbers. Ulti-
mately, the purpose of this book is to introduce methods of representing
numerical data inside a computer and techniques for manipulating this
data so as to perform common arithmetic operations.
The DIY Calculator
As we mentioned in Chapter 0, one of the best ways to learn something
and remember it afterward is by means of hands-on (“fumble and stum-
ble”) experience, which you are about to gain in huge dollops. As a key
element in this “ordeal by fire,” you are going to create a program to im-
plement a simple calculator by performing a series of interactive labora-
tories featuring the internationally acclaimed DIY Calculator.
What is a DIY Calculator and where might one be found? As fate
would have it, this little rapscallion, which was conceived and designed
by the authors, comprises a calculator front panel (the user interface dis-
cussed in the previous section) connected to a simple general-purpose
computer with a 16-bit address bus, an 8-bit data bus, some RAM and
ROM, and a number of input and output ports. But the really cunning
thing about the DIY Calculator is that, as opposed to being constructed
from physical components, it has been implemented as a virtual machine
(a simulator) that runs on your PC and is delivered on the CD-ROM ac-
companying this book.
If you haven’t already done so, install your DIY Calculator now (see
Appendix A). Once you’ve performed this installation, use the Start >
Programs > DIY Calculator > DIY Calculator command (or double-
click the DIY Calculator icon on your desktop) to invoke the little scamp
In the middle of the main DIY Calculator window is the calculator
front panel (sometimes we’ll simply refer to this as the “calculator” or
“front panel” for short). This is the graphical interface that can be used to
feed data to, display results from, and control our calculator (Figure 2-7).
c02.qxd 7/20/2005 8:24 AM Page 31
THE DIY CALCULATOR 31
File Setup Display Memory Tools Help Menu Bar
Figure 2-6. The main DIY Calculator window.
Bin Dec Hex
Sin x^y 7 8 9 / Mod Exp
Cos x^3 4 5 6 * Pi F-S
Tan x^2 1 2 3 - ( )
Log Rx 0 +/- . + =
n! 1/x A B C D E F
On/Off Reset Step Run Clear CE Back Enter
Figure 2-7. The calculator front panel.
c02.qxd 7/20/2005 8:24 AM Page 32
32 COMPUTERS AND CALCULATORS
As you can see, the calculator front panel is festooned with but-
tons with which you are soon to become intimately acquainted.
Observe that some of these buttons have been left blank for you to as-
sign your own operations. Also note that you can reconfigure the front
panel to modify the legends on the buttons, change the colors of the
legends, and so forth. These aspects of the front panel are discussed in
At the bottom left-hand side of the front panel are a group of four
special control buttons: On/Off, Reset, Step, and Run. Just to get a feel
for what’s going on, click the On/Off button to power-up the calculator
(that is, the front panel and the computer, our simulator, “behind” the
front panel). Note that the main display area fills up with “-” characters,
indicating that it’s in an uninitialized state. Similarly, the six little lights
next to the Bin, Dec, and Hex (and related) buttons, located just beneath
the main display area, all glow red to indicate that they too are in an
Try clicking the calculator’s 0 through 9 button, and note that
nothing happens whatsoever. This is because, thus far, you haven’t
loaded a program into the calculator’s memory.
Next, use the main DIY Calculator window’s Memory > Load
RAM pull-down menu to invoke a dialog offering a list of the programs
that are currently available. By default, this dialog should be looking in
the C:\DIY Calculator\Work folder; if not, set the context to this folder.
Select (click on) the test.ram file you’ll find in the Work folder and then
click the Load button to load the contents of this file into the calculator’s
Now click the front panel’s Run button to execute the program
and note that the main display is cleared and the six little lights go out.
Next, try clicking the 0 through 9 buttons again and observe what
Note that these are the only buttons that do anything; the other
function buttons have no effect (don’t play with the On/Off, Reset, Step,
or Run control buttons until instructed to do so). The reason for this is
quite simple. After clearing the display, all this particular program does is
to loop around waiting for you to click a button. If this button corre-
sponds to 0 through 9, the program copies that value back to the display;
otherwise, it ignores you and returns to looping around waiting for you
to click another button.
c02.qxd 7/20/2005 8:24 AM Page 33
When you’ve finished playing, click the On/Off button to power-down
the calculator. Now you’re really ready to rock and roll, so take a deep
breath and perform the following interactive laboratories that you’ll find
toward the back of this book:
Lab 2a: Creating a Simple Program
Lab 2b Constant Labels and .EQU Statements
Lab 2c: Driving the Front Panel’s Main Display
Lab 2d: Reading from the Front Panel’s Keypad
Lab 2e: Writing to the Front Panel’s Six LEDs
Lab 2f: Using the Memory Walker and Other Diagnostic Displays
This chapter introduced the main elements of a computer system and
described how a computer could be used in the role of a calculator.
1) What does the abbreviation CPU stand for and what is its role in a
2) What do the abbreviations ROM and RAM stand for?
3) Summarize the key features of ROM and RAM devices.
4) Name the three busses used by a computer and describe their
5) Summarize the actions of the clock and reset control signals.
6) What is the purpose of the power-on reset circuit?
7) What elements does the computer use to “talk” to the outside
8) To what do the terms word and address space refer?
9) What key services are provided by a calculator’s front panel?
10) What are the names of the CPU’s status flags?1
You will need to have performed the interactive laboratories associated with this chapter
in order to be able to answer this question.
c02.qxd 7/20/2005 8:24 AM Page 34