William Stallings Computer Organization and Architecture 7 Edition System Buses
William Stallings Computer Organization and Architecture 7 Edition System Buses
William Stallings Computer Organization and Architecture 7 Edition System Buses
Computer Organization
and Architecture
7th Edition
Chapter 3
System Buses
Program Concept
• Hardwired systems are inflexible
• General purpose hardware can do
different tasks, given correct control
signals
• Instead of re-wiring, supply a new set of
control signals
• 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 generates
control signals. To distinguish this new method of programming, a
sequence of codes or instructions is called software.
Continues
• 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 functioning
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.
What is a program?
• A sequence of steps
• For each step, an arithmetic or logical
operation is done
• For each operation, a different set of
control signals is needed
Function of Control Unit
• For each operation a unique code is
provided
—e.g. ADD, MOVE
• A hardware segment accepts the code and
issues the control signals
• We have a computer!
Components
• The Control Unit and the Arithmetic and
Logic Unit constitute the Central
Processing Unit
• Data and instructions need to get into the
system and results out
—Input/output
• Temporary storage of code and results is
needed
—Main memory
Computer Components:
Top Level View
Figure 3.2 illustrates these top-level components and
suggests the interactions among them. The CPU exchanges
data with memory. For this purpose, it typically 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 (I/OBR) register 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
numbered 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 holding these data until they can be sent on.
Instruction Cycle
• Two steps:
—Fetch
—Execute
Fetch Cycle
• Program Counter (PC) holds address of
next instruction to fetch
• Processor fetches instruction from
memory location pointed to by PC
• Increment PC
—Unless told otherwise
• Instruction loaded into Instruction
Register (IR)
• Processor interprets instruction and
performs required actions
Execute Cycle
• Processor-memory
—data transfer between CPU and main memory
• Processor I/O
—Data transfer between CPU and I/O module
• Data processing
—Some arithmetic or logical operation on data
• Control
—Alteration of sequence of operations
—e.g. jump
• Combination of above
Example of Program Execution
• 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 (MAR) and a memory buffer register
(MBR). For simplicity, these intermediate 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.
• For example, the PDP-11 processor includes an instruction,
expressed symbolically 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
Instruction Cycle State Diagram
• Instruction address calculation (iac): Determine the address of the
next instruction to be executed. Usually, this involves adding a fixed
number to the address of the previous instruction. For example, if each
instruction is 16 bits long and memory is organized into 16-bit words,
then add 1 to the previous address. If, instead, memory is organized as
individually addressable 8-bit bytes, then add 2 to the previous address.
• • Instruction fetch (if): Read instruction from its memory location into
the processor.
• • Instruction operation decoding (iod): Analyze instruction to
determine type of operation to be performed and operand(s) to be used.
• • Operand address calculation (oac): If the operation involves
reference to an operand in memory or available via I/O, then determine
the address of the operand.
• • Operand fetch (of): Fetch the operand from memory or read it in from
I/O.
• • Data operation (do): Perform the operation indicated in the
instruction.
• • Operand store (os): Write the result into memory or out to I/O .
Interrupts
• Mechanism by which other modules (e.g.
I/O) may interrupt normal sequence of
processing
• Program
—e.g. overflow, division by zero
• Timer
—Generated by internal processor timer
—Used in pre-emptive multi-tasking
• I/O
—from I/O controller
• Hardware failure
—e.g. memory parity error
• 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.
Program Flow Control
• Figure 3.7a illustrates this state of affairs.
The user program performs a series 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.
• Because the I/O operation may take a relatively long time
to complete, the I/O program is hung up waiting for the
operation to complete; hence, the user program is stopped
at the point of the WRITE call for some considerable period
of time.
Interrupt cycle
• With interrupts, the processor can be engaged in executing
other instructions while an I/O operation is in progress.
Consider the flow of control in Figure 3.7b. As before, the
user program reaches a point at which it makes a system
call in the form of a WRITE call. The I/O program that is
invoked in this case consists only of the preparation code
and the actual I/O command. After these few instructions
have been executed, control returns to the user program.
Meanwhile, the external device is busy accepting data from
computer memory and printing it. This I/O operation is
conducted concurrently with the execution of instructions
in the user program.
Interrupt Cycle
• Added to instruction cycle
• Processor checks for interrupt
—Indicated by an interrupt signal
• If no interrupt, fetch next instruction
• If interrupt pending:
—Suspend execution of current program
—Save context
—Set PC to start address of interrupt handler
routine
—Process interrupt
—Restore context and continue interrupted
program
Transfer of Control via Interrupts
Instruction Cycle with Interrupts
• The processor now proceeds to the fetch cycle and fetches
the first instruction in the interrupt handler program, which
will service the interrupt. The interrupt handler program is
generally part of the operating system. Typically, this
program determines the nature of the interrupt and
performs whatever actions are needed. In the example we
have been using, the handler determines which I/O module
generated the interrupt and may branch to a program that
will write more data out to that I/O module. When the
interrupt handler routine is completed, the processor can
resume execution of the user program at the point of
interruption. It is clear that there is some overhead involved in this
process. Extra instructions must be executed (in the interrupt handler) to
determine the nature of the interrupt and to decide on the appropriate
action. Nevertheless, because of the relatively large amount of time that
would be wasted by simply waiting on an I/O operation, the processor can
be employed much more efficiently with the use of interrupts.
Program Timing
Short I/O Wait
Program Timing
Long I/O Wait
Multiple interrupts
• Multiple interrupts can occur. For
example, a program may be receiving
data from a communications line and
printing results. The printer will generate
an interrupt every time that it completes a
print operation. The communication line
controller will generate an interrupt every
time a unit of data arrives. The unit could
either be a single character or a block,
depending on the nature of the
communications discipline.
Instruction Cycle (with Interrupts) -
State Diagram
Multiple Interrupts solution
• Disable interrupts
—Processor will ignore further interrupts whilst
processing one interrupt
—Interrupts remain pending and are checked
after first interrupt has been processed
—Interrupts handled in sequence as they occur
• A disabled interrupt simply means that the processor can and will
ignore that interrupt request signal. If an interrupt occurs during
this time, it generally remains pending and will be checked by the
processor after the processor has enabled interrupts. Thus, when
a user program is executing and an interrupt occurs, interrupts are
disabled immediately. After the interrupt handler routine
completes, interrupts are enabled before resuming the user
program, and the processor checks to see if additional interrupts
have occurred. This approach is nice and simple, as interrupts are
handled in strict sequential order.
Multiple Interrupts - Sequential
Multiple Interrupts – Nested
Multiple interrupts solution
• Define priorities
—Low priority interrupts can be interrupted by
higher priority interrupts
—When higher priority interrupt has been
processed, processor returns to previous
interrupt.
• As an example of this second approach, consider a system with three I/O
devices: a printer, a disk, and a communications line, with increasing
priorities of 2, 4, and 5, respectively. Figure 3.14, based on an example in
[TANE97], illustrates a possible sequence. A user program begins at t 0. At
t 10, a printer interrupt occurs; user information is placed on the system
stack and execution continues at the printer interrupt service routine
(ISR).While this routine is still executing, at t 15, a communications
interrupt occurs. Because the communications line has higher priority than
the printer, the interrupt is honored. The printer ISR is interrupted, its state
is pushed onto the stack, and execution continues at the communications
ISR. While this routine is executing, a disk interrupt occurs (t 20). Because
this interrupt is of lower priority, it is simply held, and the communications
ISR runs to completion.
Time Sequence of Multiple Interrupts
Connecting
• All the units must be connected
• Different type of connection for different
type of unit
—Memory
—Input/Output
—CPU
Computer Modules
Memory Connection
• Receives and sends data
• Receives addresses (of locations)
• Receives control signals
—Read
—Write
—Timing
Input/Output Connection(1)
• Similar to memory from computer’s
viewpoint
• Output
—Receive data from computer
—Send data to peripheral
• Input
—Receive data from peripheral
—Send data to computer
Input/Output Connection(2)
• Receive control signals from computer
• Send control signals to peripherals
—e.g. spin disk
• Receive addresses from computer
—e.g. port number to identify peripheral
• Send interrupt signals (control)
CPU Connection
• Reads instruction and data
• Writes out data (after processing)
• Sends control signals to other units
• Receives (& acts on) interrupts
Buses
A bus is a communication pathway connecting two or more
devices. A key characteristic of a bus is that it is a shared
transmission medium. Multiple devices connect to the bus,
and a signal transmitted by any one device is available for
reception by all other devices attached to the bus. If two
devices transmit during the same time period, their signals
will overlap and become garbled. Thus, only one device at a
time can successfully transmit.