Module-3-23CS302
Module-3-23CS302
Basic Structure of
Computers
Introduction
•Computers have become part and parcel of our daily lives.
–They are everywhere (embedded systems?)
–Laptops, tablets, mobile phones, intelligent appliances.
•Computer Architecture:
–How to integrate the components to build a computer
system to achieve a desired level of performance.
–Analogy: architect’s task during the planning of a building
(overall layout, floorplan, etc.).
Functional Units
Arithmetic
Input and
logic
Memory
Output Control
I/O Processor
• Data
Used as operands by the instructions
Source program
Memory Unit
• Store programs and data
–Two main types of memory subsystems.
•Primary or Main memory, which stores the active instructions
and data for the program being executed on the processor.
•Secondary memory, which is used as a backup and stores all
active and inactive programs and data, typically as files.
–The processor only has direct access to the primary memory.
–In reality, the memory system is implemented as a
hierarchy of several levels.
•Registers, cache, primary memory, secondary memory.
•Objective is to provide faster memory access at affordable
cost.
c)Magnetic Disk
which uses direction of magnetization of tiny magnetic
particles on a metallic surface to store data.
Access times vary depending on the location being
accessed, and is used as secondary memory.
d)Flash Memory
which is replacing magnetic disks as secondary memory
devices.
They are faster, but smaller in size as compared to disk.
Inside the Processor
–Also called Central Processing Unit (CPU).
–Consists of a Control Unit and an Arithmetic Logic Unit (ALU).
•All calculations happen inside the ALU.
•The Control Unit generates sequence of control signals to carry
out all operations.
–The processor fetches an instruction from memory for execution.
•An instruction specifies the exact operation to be carried out.
•It also specifies the data that are to be operated on.
•A program refers to a set of instructions that are required to
carry out some specific task (e.g. sorting a set of numbers).
What is the role of ALU?
appropriate encoding.
MAR MDR
Control
PC R0
R1
Processor
IR
ALU
Rn - 1
n general purpose
registers
M
A
R
PROCESSOR PRIMARY
M
MEMORY
D
R
Control Signals
•Memory considered as a linear array of storage locations
(bytes or words) each with unique address.
a)ADD LOCA, R1
• Add the contents of memory location LOCA (i.e. address of
the memory location is LOCA) to the contents of register R1.
• R1 R1 + Mem[LOCA]
b)ADD R1, R2
• Add the contents of register R2 to the contents of register
R1.
• R2 R1 + R2
Execution of ADD LOCA, R1
•Assume that the instruction is stored in memory location 1000,
the initial value of R1 is 50, and LOCA is 5000.
• Before the instruction is executed, PC contains 1000. PC=1000
• Content of PC is transferred to MAR. MAR PC
• READ request is issued to memory unit.
• The instruction is fetched to MDR. MDR <- Mem[MAR]
• Content of MDR is transferred to IR. IR <- MDR
• PC is incremented to point to the next instruction. PC <-PC + 4
• The instruction is decoded by the control unit.
• R – clock rate
N S
T
R
How to improve T?
Pipeline and Superscalar Operation
• Instructions are not necessarily executed one after
another.
• The value of S doesn’t have to be the number of clock
cycles to execute one instruction.
• Pipelining – overlapping the execution of successive
instructions.
• Add R1, R2, R3
• The contents of R1 & R2 are first transferred to the inputs
of ALU.
• After the addition operation is performed, the sum is
transferred to R3.
• The processor can read the next instruction from the
memory, while the addition operation is being performed.
Pipeline and Superscalar Operation
• In the ideal case if all instructions are overlapped to the
maximum degree possible the execution proceeds at the
rate of one instruction completed in each clock cycle.
• Individual instructions still require several clock cycles to
complete. But for the purpose of computing T, effective
value of S is 1.
• A higher degree of concurrency can be achieved if multiple
instructions pipelines are implemented in the processor.
• it becomes possible to start the execution of several
instructions in every clock cycle. This mode of operation is
called superscalar execution.
Clock Rate
• There are two possibilities for increasing the clock rate ‘R’.
Improving the IC technology makes logical circuit faster, which
reduces the time of execution of basic steps. This allows the clock
period P, to be reduced and the clock rate R to be increased.
Reducing the amount of processing done in one basic step also
makes it possible to reduce the clock period P.
• Increases in R that are entirely caused by improvements in IC
technology affect all aspects of the processor’s operation equally
except the time to access the main memory.
Performance Measurement
• the evaluation of ‘T’ is highly complex. Moreover the parameters like the clock
speed and various architectural features are not reliable indicators of the
expected performance.
• Measure computer performance using benchmark programs.
• The performance measure is the time taken by the computer to execute a given
bench mark.
• Initially some attempts were made to create artificial programs that could be
used as bench mark programs.
• But synthetic programs do not properly predict the performance obtained
when real application programs are run.
Performance Measurement
8 0 to 28-1 (255)
16 0 to 216-1 (65535)
32 0 to 232-1
(4294967295)
64 0 to 264-1
•An n-bit binary integer:
b b …bbb
n-1 n-2 2 1 0
bn-1 bn-2 b1 b0
Sign Magnitude
Sign and Magnitude Representation
-7 +0
-6 1111 0000 +1
1110 0001
-5 +2 +
1101 0010
-4 1100 0011 +3 0 100 = + 4
•Basic idea:
–Positive numbers are represented exactly as in sign-magnitude
form.
–Negative numbers are represented in 1’s complement form.
B V alues represented
Sign and
b3 b2b1b0 magnitude 1' s complement 2' s complement
0 1 1 1 +7 +7 + 7
0 1 1 0 +6 +6 + 6
0 1 0 1 +5 +5 + 5
0 1 0 0 +4 +4 + 4
0 0 1 1 +3 +3 + 3
0 0 1 0 +2 +2 + 2
0 0 0 1 +1 +1 + 1
0 0 0 0 +0 +0 + 0
1 0 0 0 - 0 -7 - 8
1 0 0 1 - 1 -6 - 7
1 0 1 0 - 2 -5 - 6
1 0 1 1 - 3 -4 - 5
1 1 0 0 - 4 -3 - 4
1 1 0 1 - 5 -2 - 3
1 1 1 0 - 6 - 1 - 2
1 1 1 1 - 7 -0 - 1
Subtraction:
X-Y, perform the 2’s complement of Y and then add it
to X as in addition. Answer to be in the range
-2n-1 to +2n-1 -1
2’s-Complement Add and Subtract Operations
5 0101 -7 1001
3 0011 -2 1100
-8 1000 7 10111
Overflow Overflow
5 0101 -3 1101
2 0010 -5 1011
7 0111 -8 11000
No overflow No overflow
When the result of arithmetic operation is outside the range,
then it is arithmetic Overflow
Memory Locations and Addresses
• Number and character operands, as well as
instructions, are stored in the memory of a
computer.
• Modern computers have word lengths that
typically range from 16 to 64 bits. If the word
length of a computer is 32 bits, a single word
can store a 32-bit 2’s complement number or
four ASCII characters
Memory Locations and Addresses
n bits
•
•
•
last word
b 31 b 30 b1 b0
•
•
•
Sign bit: b 31= 0 for positive numbers
b 31= 1 for negative numbers
⚫ I/O devices and the memory may share the same address space:
Memory-mapped I/O.
⚫Any machine instruction that can access memory can be used to
transfer data to or from an I/O device.
.
⚫ I/O devices and the memory may have different address spaces:
I/O mapped I/O
⚫Special instructions to transfer data to and from I/O devices.
⚫I/O devices may have to deal with fewer address lines.
⚫In fact, address lines may be shared between I/O devices and
memory, with a control signal to indicate whether it is a memory
address or an I/O address.
86
ACCESSING I/O DEVICES
Address lines
Bus Data lines
Control lines
Interrupt
occur i
sher
e i +1
M
•Processor is executing the instruction located at address i when an
interrupt occurs.
•Routine executed in response to an interrupt request is called the
interrupt-service routine.
•When an interrupt occurs, control must be transferred to the
interrupt service routine.
•But before transferring control, the current contents of the PC (i+1),
must be saved in a known
location.
•This will enable the return-from-interrupt instruction to resume
execution at i+1.
•Return address, or the contents of the PC are usually stored on the
processor stack.
Interrupts (contd..)
⚫ Treatment of an interrupt-service routine is very similar to that of a
subroutine.
⚫ However there are significant differences:
⚫ A subroutine performs a task that is required by the calling program.
⚫ Interrupt-service routine and the program that it interrupts may
belong to different users.
⚫ As a result, before branching to the interrupt-service routine, not only
the PC, but other information such as condition code flags, and
processor registers used by both the interrupted program and the
interrupt service routine must be stored.
⚫ This will enable the interrupted program to resume execution upon
return from interrupt service routine.
Interrupts (contd..)
⚫Saving and restoring information , Increases the total execution
time.
⚫ Saving and restoring information can be done automatically by the
processor or explicitly by program instructions.
⚫Saving and restoring registers involves memory transfers:
⚫the delay between the time an interrupt request is received, and the
start of execution of the interrupt-service routine. This delay is called
interrupt latency.
⚫ In order to reduce the interrupt latency, most processors save only the
minimal amount of information:
⚫This minimal amount of information includes Program Counter and
processor status registers.
⚫ Any additional information that must be saved, must be saved explicitly by
the program instructions at the beginning of the interrupt service routine.
Interrupts (contd..)
• When a processor receives an interrupt-request, it must branch
to the interrupt service routine.
• It must also inform the device that it has recognized the
interrupt request.
• This can be accomplished in two ways:
– Some processors have an explicit interrupt-acknowledge
control signal for this purpose.
– In other cases, the data transfer that takes place between
the device and the processor can be used to inform the
device.
Enabling & Disabling Interrupt
⚫ Interrupt-requests interrupt the execution of a program, and may alter
the intended sequence of events:
⚫ Sometimes such alterations may be undesirable, and must not be
allowed.
⚫ For example, the processor may not want to be interrupted by the
same device while executing its interrupt-service routine.
⚫ Processors generally provide the ability to enable and disable such
interruptions as desired.
⚫ One simple way is to provide machine instructions such as Interrupt-
enable and Interrupt-disable for this purpose.
⚫ To avoid interruption by the same device during the execution of an
interrupt service routine:
⚫ First instruction of an interrupt service routine can be Interrupt-
disable.
⚫ Last instruction of an interrupt service routine can be Interrupt-
enable.
Interrupt: Handling Multiple devices
⚫ Multiple I/O devices may be connected to the processor and the
memory via a bus. Some or all of these devices may be capable of
generating interrupt requests.
⚫ Each device operates independently, and hence no definite order
can be imposed on how the devices generate interrupt requests?
⚫ How does the processor know which device has generated an
interrupt?
⚫ How does the processor know which interrupt service routine needs to
be executed?
⚫ When the processor is executing an interrupt service routine for one
device, can other device interrupt the processor?
⚫ If two interrupt-requests are received simultaneously, then how to
break the tie?
Interrupt: Handling Multiple devices
⚫ Consider a simple arrangement where all devices send their interrupt-
requests over a single control line in the bus.
⚫ When the processor receives an interrupt request over this control line,
how does it know which device is requesting an interrupt?
⚫ This information is available in the status register of the device
requesting an interrupt:
⚫ The status register of each device has an IRQ bit which it sets to 1
when it requests an interrupt.
⚫ Interrupt service routine can poll the I/O devices connected to the bus.
The first device with IRQ equal to 1 is the one that is serviced.
⚫ Polling mechanism is easy, but time consuming to query the status bits of
all the I/O devices connected to the bus.
Interrupt: Handling Multiple devices
• The device requesting an interrupt may identify itself directly to
the processor.
– Device can do so by sending a special code (4 to 8 bits) the
processor over the bus.
– Code supplied by the device may represent a part of the
starting address of the interrupt-service routine.
• Usually the location pointed to by the interrupting device is used
to store the starting address of the interrupt-service routine.
Interrupt: Handling Multiple devices
⚫ How does the processor know which device has generated an
interrupt?
⚫ How does the processor know which interrupt service routine needs to
be executed?
⚫ When the processor is executing an interrupt service routine for one
device, can other device interrupt the processor?
⚫ If two interrupt-requests are received simultaneously, then how to
break the tie?
Interrupt: Handling Multiple devices
⚫ Consider a simple arrangement where all devices send their interrupt-
requests over a single control line in the bus.
⚫ When the processor receives an interrupt request over this control line,
how does it know which device is requesting an interrupt?
⚫ This information is available in the status register of the device
requesting an interrupt:
⚫ The status register of each device has an IRQ bit which it sets to 1
when it requests an interrupt.
⚫ Interrupt service routine can poll the I/O devices connected to the bus.
The first device with IRQ equal to 1 is the one that is serviced.
⚫ Polling mechanism is easy, but time consuming to query the status bits
of all the I/O devices connected to the bus.
Interrupt: Handling Multiple devices
– Device can do so by The device requesting an interrupt
may identify itself directly to the processor.
– ending a special code (4 to 8 bits) the processor over the bus.
– Code supplied by the device may represent a part of the starting address of the
interrupt-service routine.
• Usually the location pointed to by the interrupting device is
used to store the starting address of the interrupt-service
routine.
Interrupt: Handling Multiple devices
INTA1 INTA p
Priority
arbitration
•Each device has a separate interrupt-request and
interrupt-acknowledge line.
•Each interrupt-request line is assigned a different
priority level.
•Interrupt requests received over these lines are sent to a
priority arbitration circuit in the processor.
•If the interrupt request has a higher priority level than
the priority of the processor, then the request is
accepted.
Interrupt: Handling Multiple devices
Polling scheme:
I NTR
Processor
IN T R p
Device Device
INTA p
Priority arbitration
circuit
•Devices are organized into groups.
•Each group is assigned a different priority level.
•All the devices within a single group share an interrupt-
request line, and are connected to form a daisy chain.
Interrupt Hardware
Exceptions
⚫ In general, the term exception is used to refer to any event that
causes an interruption.
⚫ Interrupt-requests from I/O devices is one type of an exception.
⚫ Other types of exceptions are:
⚫ Recovery from errors
⚫ Debugging
⚫ Privilege exception
Exceptions
⚫ Many sources of errors in a processor. For example:
⚫ Error in the data stored.
⚫ Error during the execution of an instruction.
⚫ When such errors are detected, exception processing is initiated.
⚫ Processor takes the same steps as in the case of I/O interrupt-request.
⚫ It suspends the execution of the current program, and starts executing an
exception-service routine.
⚫ Difference between handling I/O interrupt-request and handling
exceptions due to errors:
⚫ In case of I/O interrupt-request, the processor usually completes the
execution of an instruction in progress before branching to the interrupt-
service routine.
⚫ In case of exception processing however, the execution of an instruction in
progress usually cannot be completed.
Exceptions
• Certain instructions can be executed only when the processor is in
the supervisor mode. These are called privileged instructions.
• If an attempt is made to execute a privileged instruction in the user
mode, a privilege exception occurs.
• Privilege exception causes:
– Processor to switch to the supervisor mode,
– Execution of an appropriate exception-servicing routine.