talk about caches.)
The File-Clerk Model Revisited and Expanded
To return to our file-clerk metaphor, we can think of main memory as a
document storage room located on another floor and the registers as a
small, personal filing cabinet where the file clerk places the papers on
which he’s currently working. The clerk doesn’t really know anything
Basic Computing Concepts
9
about the document storage room—what it is or where it’s located—because
his desk and his personal filing cabinet are all he concerns himself with. For
documents that are in the storage room, there’s another office worker, the
office secretary, whose job it is to locate files in the storage room and retrieve them for the clerk.
This secretary represents a few different units within the processor, all
of which we’ll meet Chapter 4. For now, suffice it to say that when the boss
wants the clerk to work on a file that’s not in the clerk’s personal filing
cabinet, the secretary must first be ordered, via a message from the boss, to
retrieve the file from the storage room and place it in the clerk’s cabinet so
that the clerk can access it when he gets the order to begin working on it.
An Example: Adding Two Numbers
To translate this office example into computing terms, let’s look at how the
computer uses main memory, the register file, and the ALU to add two
numbers.
To add two numbers stored in main memory, the computer must
perform these steps:
1.
Load the two operands from main memory into the two source registers.
2.
Add the contents of the source registers and place the results in the
destination register, using the ALU. To do so, the ALU must perform
these steps:
a.
Read the contents of registers A and B into the ALU’s input ports.
b.
Add the contents of A and B in the ALU.
c.
Write the result to register C via the ALU’s output port.
3.
Store the contents of the destination register in main memory.
Since steps 2a, 2b, and 2c all take a trivial amount of time to complete,
relative to steps 1 and 3, we can ignore them. Hence our addition looks
like this:
1.
Load the two operands from main memory into the two source registers.
2.
Add the contents of the source registers, and place the results in the des-
tination register, using the ALU.
3.
Store the contents of the destination register in main memory.
The existence of main memory means that the user—the boss in our
filing-clerk analogy—must manage the flow of information between main
memory and the CPU’s registers. This means that the user must issue
instructions to more than just the processor’s ALU; he or she must also
issue instructions to the parts of the CPU that handle memory traffic.
Thus, the preceding three steps are representative of the kinds of instruc-
tions you find when you take a close look at the code stream.
10
Chapter 1
A Closer Look at the Code Stream: The Program
At the beginning of this chapter, I defined the code stream as consisting of
“an ordered sequence of operations,” and this definition is fine as far as it
goes. But in order to dig deeper, we need a more detailed picture of what the
code stream is and how it works.
The term operations suggests a series of simple arithmetic operations
like addition or subtraction, but the code stream consists of more than just
arithmetic operations. Therefore, it would be better to say that the code
stream consists of an ordered sequence of instructions . Instructions, generally speaking, are commands that tell the whole computer—not just the ALU,
but multiple parts of the machine—exactly what actions to perform. As we’ve
seen, a computer’s list of potential actions encompasses more than just
simple arithmetic operations.
General Instruction Types
Instructions are grouped into ordered lists that, when taken as a whole,
tell the different parts of the computer how to work together to perform a
specific task, like grayscaling an image
Under the Cover of the Moon (Cobblestone)