Ciclo de Búsqueda y Ejecución Stalling
Ciclo de Búsqueda y Ejecución Stalling
Ciclo de Búsqueda y Ejecución Stalling
and let us add to the general-purpose hardware a segment that can accept a code
and generate control signals (Figure 3.1b).
Programming is now much easier. Instead of rewiring the hardware for each
new program, all we need to do is provide a new sequence of codes. Each code is, in
effect, an instruction, and part of the hardware interprets each instruction and gen-
erates control signals. To distinguish this new method of programming, a sequence
of codes or instructions is called software.
Figure 3.1b indicates two major components of the system: an instruction
interpreter and a module of general-purpose arithmetic and logic functions. These
two constitute the CPU. Several other components are needed to yield a function-
ing computer. Data and instructions must be put into the system. For this we need
some sort of input module. This module contains basic components for accepting
data and instructions in some form and converting them into an internal form
of signals usable by the system. A means of reporting results is needed, and this
is in the form of an output module. Taken together, these are referred to as I/O
components.
One more component is needed. An input device will bring instructions and
data in sequentially. But a program is not invariably executed sequentially; it may
jump around (e.g., the IAS jump instruction). Similarly, operations on data may
require access to more than just one element at a time in a predetermined sequence.
Thus, there must be a place to temporarily store both instructions and data. That
module is called memory, or main memory, to distinguish it from external storage or
peripheral devices. Von Neumann pointed out that the same memory could be used
to store both instructions and data.
Figure 3.2 illustrates these top-level components and suggests the interac-
tions among them. The CPU exchanges data with memory. For this purpose, it typ-
ically makes use of two internal (to the CPU) registers: a memory address register
(MAR), which specifies the address in memory for the next read or write, and a
memory buffer register (MBR), which contains the data to be written into memory
or receives the data read from memory. Similarly, an I/O address register (I/OAR)
specifies a particular I/O device. An I/O buffer register (I/OBR) is used for the
exchange of data between an I/O module and the CPU.
A memory module consists of a set of locations, defined by sequentially num-
bered addresses. Each location contains a binary number that can be interpreted as
either an instruction or data. An I/O module transfers data from external devices to
CPU and memory, and vice versa. It contains internal buffers for temporarily hold-
ing these data until they can be sent on.
Having looked briefly at these major components, we now turn to an overview
of how these components function together to execute programs.
I/O AR
Data
Execution
unit Data
I/O BR
Data
Data
PC = Program counter
Buffers IR = Instruction register
MAR = Memory address register
MBR = Memory buffer register
I/O AR = Input/output address register
I/O BR = Input/output buffer register
Figure 3.2 Computer Components: Top-Level View
the key elements of program execution. In its simplest form, instruction processing
consists of two steps: The processor reads (fetches) instructions from memory one
at a time and executes each instruction. Program execution consists of repeating
the process of instruction fetch and instruction execution. The instruction execution
may involve several operations and depends on the nature of the instruction (see, for
example, the lower portion of Figure 2.4).
The processing required for a single instruction is called an instruction cycle.
Using the simplified two-step description given previously, the instruction cycle is
depicted in Figure 3.3. The two steps are referred to as the fetch cycle and the execute
cycle. Program execution halts only if the machine is turned off, some sort of unrecov-
erable error occurs, or a program instruction that halts the computer is encountered.
always increments the PC after each instruction fetch so that it will fetch the next
instruction in sequence (i.e., the instruction located at the next higher memory
address). So, for example, consider a computer in which each instruction occupies
one 16-bit word of memory. Assume that the program counter is set to memory loca-
tion 300, where the location address refers to a 16-bit word. The processor will next
fetch the instruction at location 300. On succeeding instruction cycles, it will fetch
instructions from locations 301, 302, 303, and so on. This sequence may be altered, as
explained presently.
The fetched instruction is loaded into a register in the processor known as
the instruction register (IR). The instruction contains bits that specify the action
the processor is to take. The processor interprets the instruction and performs the
required action. In general, these actions fall into four categories:
■■ Processor-memory: Data may be transferred from processor to memory or
from memory to processor.
■■ Processor-I/O: Data may be transferred to or from a peripheral device by
transferring between the processor and an I/O module.
■■ Data processing: The processor may perform some arithmetic or logic oper-
ation on data.
■■ Control: An instruction may specify that the sequence of execution be altered.
For example, the processor may fetch an instruction from location 149, which
specifies that the next instruction be from location 182. The processor will
remember this fact by setting the program counter to 182. Thus, on the next
fetch cycle, the instruction will be fetched from location 182 rather than 150.
An instruction’s execution may involve a combination of these actions.
Consider a simple example using a hypothetical machine that includes the
characteristics listed in Figure 3.4. The processor contains a single data register,
called an accumulator (AC). Both instructions and data are 16 bits long. Thus, it is
convenient to organize memory using 16-bit words. The instruction format provides
4 bits for the opcode, so that there can be as many as 24 = 16 different opcodes, and
up to 212 = 4096 (4K) words of memory can be directly addressed.
Figure 3.5 illustrates a partial program execution, showing the relevant por-
tions of memory and processor registers.1 The program fragment shown adds the
contents of the memory word at address 940 to the contents of the memory word at
1
Hexadecimal notation is used, in which each digit represents 4 bits. This is the most convenient nota-
tion for representing the contents of memory and registers when the word length is a multiple of 4. See
Chapter 9 for a basic refresher on number systems (decimal, binary, hexadecimal).
110 Chapter 3 / A Top-Level View of Computer Function and Interconnection
0 3 4 15
Opcode Address
0 1 15
Magnitude
Step 1 Step 2
Step 3 Step 4
Step 5 Step 6
address 941 and stores the result in the latter location. Three instructions, which can
be described as three fetch and three execute cycles, are required:
1. The PC contains 300, the address of the first instruction. This instruction (the
value 1940 in hexadecimal) is loaded into the instruction register IR, and
the PC is incremented. Note that this process involves the use of a memory
address register and a memory buffer register. For simplicity, these intermedi-
ate registers are ignored.
2. The first 4 bits (first hexadecimal digit) in the IR indicate that the AC is to be
loaded. The remaining 12 bits (three hexadecimal digits) specify the address
(940) from which data are to be loaded.
3. The next instruction (5941) is fetched from location 301, and the PC is
incremented.
4. The old contents of the AC and the contents of location 941 are added, and
the result is stored in the AC.
5. The next instruction (2941) is fetched from location 302, and the PC is
incremented.
6. The contents of the AC are stored in location 941.
In this example, three instruction cycles, each consisting of a fetch cycle and an
execute cycle, are needed to add the contents of location 940 to the contents of 941.
With a more complex set of instructions, fewer cycles would be needed. Some older
processors, for example, included instructions that contain more than one memory
address. Thus, the execution cycle for a particular instruction on such processors
could involve more than one reference to memory. Also, instead of memory refer-
ences, an instruction may specify an I/O operation.
For example, the PDP-11 processor includes an instruction, expressed symboli-
cally as ADD B,A, that stores the sum of the contents of memory locations B and A
into memory location A. A single instruction cycle with the following steps occurs:
■■ Fetch the ADD instruction.
■■ Read the contents of memory location A into the processor.
■■ Read the contents of memory location B into the processor. In order that the
contents of A are not lost, the processor must have at least two registers for
storing memory values, rather than a single accumulator.
■■ Add the two values.
■■ Write the result from the processor to memory location A.
Thus, the execution cycle for a particular instruction may involve more than one
reference to memory. Also, instead of memory references, an instruction may specify
an I/O operation. With these additional considerations in mind, Figure 3.6 provides a
more detailed look at the basic instruction cycle of Figure 3.3. The figure is in the form
of a state diagram. For any given instruction cycle, some states may be null and others
may be visited more than once. The states can be described as follows:
■■ Instruction address calculation (iac): Determine the address of the next
instruction to be executed. Usually, this involves adding a fixed number to
112 Chapter 3 / A Top-Level View of Computer Function and Interconnection
Multiple Multiple
operands results
Interrupts
Virtually all computers provide a mechanism by which other modules (I/O, memory)
may interrupt the normal processing of the processor. Table 3.1 lists the most com-
mon classes of interrupts. The specific nature of these interrupts is examined later in
this book, especially in Chapters 7 and 14. However, we need to introduce the concept
now to understand more clearly the nature of the instruction cycle and the impli-
cations of interrupts on the interconnection structure. The reader need not be con-
cerned at this stage about the details of the generation and processing of interrupts,
but only focus on the communication between modules that results from interrupts.
Interrupts are provided primarily as a way to improve processing efficiency.
For example, most external devices are much slower than the processor. Suppose
that the processor is transferring data to a printer using the instruction cycle scheme
of Figure 3.3. After each write operation, the processor must pause and remain
idle until the printer catches up. The length of this pause may be on the order of
many hundreds or even thousands of instruction cycles that do not involve memory.
Clearly, this is a very wasteful use of the processor.
Figure 3.7a illustrates this state of affairs. The user program performs a ser-
ies of WRITE calls interleaved with processing. Code segments 1, 2, and 3 refer to
sequences of instructions that do not involve I/O. The WRITE calls are to an I/O
program that is a system utility and that will perform the actual I/O operation. The
I/O program consists of three sections:
■■ A sequence of instructions, labeled 4 in the figure, to prepare for the actual I/O
operation. This may include copying the data to be output into a special buffer
and preparing the parameters for a device command.
■■ The actual I/O command. Without the use of interrupts, once this command
is issued, the program must wait for the I/O device to perform the requested
function (or periodically poll the device). The program might wait by simply
repeatedly performing a test operation to determine if the I/O operation is done.
■■ A sequence of instructions, labeled 5 in the figure, to complete the operation.
This may include setting a flag indicating the success or failure of the operation.