Anda di halaman 1dari 128

CCB-581: Computer Architecture

1
Text-Books
William Stallings, “Computer Organization and Architecture –
Designing for Performance”, Ninth Edition.

Morris Mano, “Computer System Architecture”, Sixth Ed.

David A. Patterson and John L. Hennessy, “Computer


Organization and Design: The hardware/software interface”,
Fifth Edition.

2
Computer Architecture
 The architecture is concerned with the attributes (structure and behaviour) of the
computer visible to the programmer
 Instruction Set
 Instruction Formats
 Specific Registers and their roles
 Number of bits used for data representation
 I/O mechanisms
 Addressing techniques.
 e.g. Is there a multiply instruction?

 It is the external of a computer that is essential to be properly understood by the


programmer.

 All Intel x86 family share the same basic architecture


Computer Organization
 Organization is concerned with the way how-
 The hardware components(CPU, memory and peripheral devices) operate
 The hardware components connected together
 e.g. Is there a hardware multiply unit or is it done by repeated addition?

 It helps to understand the internal operations carried out by a computer

Architecture-An Application
interface Programs
between
software and
System
hardware.
Programs

Architecture

Organization
Computer Design

 Design is concerned with the hardware design of


the computer.
 What hardware to be used ?
 How they are to be connected ?
Computer
❑ An automatic electronic device for performing
calculations or controlling operations on inputs those can
be expressed in numerical or logical terms.

❑ It is a device that
❑ Accepts input
❑ Executes instructions
❑ Returns results.

6
Computer
❑ It consists of following components
❑ Central Processing Unit
❑ Input

❑ Output

❑ Storage

7
Stored-Program Computer
 A stored-program computer is a computer that stores program instructions in
electronic memory.
 This contrasts with machines where the program instructions are stored
on plug-boards /punched card/similar mechanisms.

Plug-boards
8
Stored-Program Computer

 Stored-Program Computers

 Von-Neumann architecture
 A computer which stores a program data and instruction in
the same memory.

 Harvard architecture
 A computer which has separate memories for storing
program and data.

9
Von-Neumann Architecture
• Hungarian-American mathematician John von Neumann.
• A computer which stores a program data and instruction data in the
same memory.
• The programs are executed in sequential manner.
• The sequential execution is maintained by special register (Program
Counter)

1
0
Von-Neumann Bottleneck
There exists a single data path between the CPU and main memory.
 Due to shared bus, an instruction fetch and a data operation cannot
occur at the same time thus leading to performance slowdown.
 This is known as von Neumann bottleneck.

1
1
Components of a Computer

Monitor Speaker
(output) (output) System unit
(processor, memory…)

Printer
(output)

Storage devices
(CD-RW, Floppy, Hard
disk, zip,…)
Mouse
(input)
Scanner Keyboard
(input) (input)

1
2
Central Processing Unit (CPU)
➢ The CPU, the brain of the computer.
➢ Also known as microprocessor: Housed on a tiny silicon chip

➢ Chip contains millions of switches and pathways that help your


computer make important decisions.
➢ knows which switches to turn on and which to turn off
because it receives its instructions from computer
programs (software).

➢ CPU has two primary sections:


➢ Arithmetic/logic unit
➢ Control unit

1
3
Arithmetic logic Unit
 Performs arithmetic computations and logical operations; by
combining these two operations the ALU can execute complex
tasks.
 Arithmetic operations include addition, subtractions,
multiplication, and division.
 Logical operations involve comparisons.

14
Control Unit
 It is the “boss” and coordinates all of the CPU’s activities.
 Uses programming instructions.
 It controls the flow of information through the processor by
controlling what happens inside the processor.
 Send control signal to all associated units.

15
Input Devices

➢ In computing, an input device is a piece of hardware equipment


used to receive data and control signals.

➢ The input devices are operated and controlled by the control unit
(CU).

16
Input Devices

• Keyboard • Touch screen


• Mouse/Trackball • Bar code reader
• Joystick • Scanner
• Microphone
• Light pen
• Graphics Tablet
• Pointing Stick
• Digital Cameras
• Touchpad

17
Output Unit
 After the data has been processed, the results are sent in the form
of useful information to output units.
 The input devices are operated and controlled by the control unit
(CU).

18
Computer Output Devices
Monitor: screen that display Speakers: allow you to
information such as text, hear voice, music, and
numbers, and pictures- other sounds from your
softcopy. computer.

Printer: gives you Modem: allows you to use


information from the your computer to
computer in printed form – communicate with other
hardcopy. computers.

19
Memory

 Memory is used to store data

 The contents of main memory can be transferred to


auxiliary storage devices such as hard disks, floppy
diskettes, zip disks, compact disks, or USB flash disk.

 Two Types
Short term : Random Access Memory (RAM)
Long term : Read Only Memory (ROM)

20
Random Access Memory (RAM)

• Also known as the main memory.


• Memory on the motherboard
• Data, information, and program instructions are stored
temporarily on a RAM chip or a set of RAM chips.

• This memory is considered volatile.


 When the computer is turned off or if there is loss of
power, what ever is stored in RAM disappears.

• The CPU can read from and write to RAM.

21
Read Only Memory (ROM)

• Memory on the motherboard


• The specific instructions that are needed for the computer to operate are
stored.
• This memory is non-volatile and your computer can only read from a ROM
chip.

• The instructions remain on the chip regardless if the power is turned on or


off.

• Most common is the BIOS ROM; where the computer uses instructions
contained on this chip to boot or start the system when you turn on your
computer.

22
Applications of Computers
 Accounts
 Games
 Education
 Research
 On-line banking
 Smart ID cards
 Supermarkets
 Working from home (Tele-working)
 Internet

23
Concept of Programming
Programming Terminology
➢ Instruction: An instruction is an order given to the CPU to
perform a unit of task. (Add, Subtract, Load, Move, etc.)

➢ Program: A set of instructions in order to perform a logical task.


(Add two numbers; Find factorial etc.)

➢ Software refers to programs (+documentation) that make the


computer perform some work. (Calculator, Operating System,
etc.)

➢ Note:
➢ When you have written a program, the computer will
behave exactly as you have instructed it.
➢ It will do no more or no less than what is contained in your
instructions.
25
Why Programming (ML/AL/HLL)?
 How humans interact with each other?
 Using a language , the basic elements of a language are the letters,
right?

 What you do with these letters?


 You combine them, form a meaningful word or sentence
 If you say h-o-u-s-e , is a nonsense, but if you say house , people
will understand you.

 Language is the medium of communication.

 For computers, Programming Language provides the medium for


communication to outside world.

26
Historical Background
➢ As early practice of rewiring circuits proved too cumbersome,
computer languages began to appear in order to control the
computer.

➢ The first, machine language, was constructed of ones and zeros


using binary codes.

➢ More efficient than rewiring circuits of machine to program it.


➢ still time-consuming to develop a program due
to sheer number of program codes required

27
Historical Background
 Once systems such as UNIVAC became available in early 1950s,
assembly language was used to simplify entering binary code.

 Assembler allows programmer to use mnemonic codes…


 such as ADD for addition

 In place of a binary number.


 such as 0100 0111

 Assembly language is an aid to programming.

28
Historical Background
As assembly language is also tedious for business person, therefore,
many high-level programming language has been developed
 FLOWMATIC.

 FORTRAN (FORmula TRANslator)


 ALGOL (ALGOrithmic Language)
 COBOL (COmputer Business Oriented Language).
 RPG (Report Program Generator)
 BASIC, C#, C/C++, Java, PASCAL etc.

29
Programming Language

➢ A programming language is a formal language designed


to communicate instructions to a computer.

➢ Each language has well defined syntax.

➢ There are two major types of programming languages:


➢Low-level languages
➢ Machine Language
➢ Assembly Language
➢High-level languages

30
Low-Level Language
➢ Low-level languages are referred to as 'low' because they are
very close to how different hardware elements of a
computer actually communicate with each other.

➢ Low-level languages are machine oriented and require


extensive knowledge of computer hardware and its
configuration.

➢ In a low-level language, it is necessary for the programmer to


know the instruction set of the CPU in order to program the
computer.

➢ Two low-level languages


➢ Machine language
➢ Assembly language.

31
Machine Language
➢ It is the native language that the CPU “speaks” and
“understands”.

➢ It does not need to be translated.

➢ All instructions use binary notation and are written as a


string of 1s and 0s.

➢ It is possible to write an entire program in machine


language. However, this is very time consuming and
difficult to read and understand.

32
Assembly Language
➢ A first step to improve programming structure to make
machine language more readable by humans.

➢ An assembly language consists of a set of symbols and


letters (MOVE, ADD, SUB and END.).

➢ An assembler is a program that reads the codes the


programmer writes in assembly language and
“assembles” a machine language program based on those
codes.

➢ Assembly languages are still pretty difficult to


understand. This is why high-level languages have been
developed.
33
Comparing Machine Language & Assembly Language

➢ For example, the machine code for adding two integers might be:
01000001 00111010 00111101
01000001 00101011 01000010
01000011 00111010
01000111 00111110

➢ While the assembly language code might be:


LOAD B 63 ; Initialize B with 63
LOAD A 66 ; Initialize B with 63 (Note: A is accumulator register)
ADD B ; Add the value of A with B and Store in A
STORE C ; Store the value of A in C

➢ This causes the number in A to be added to the number in B, and the


result is stored for later use in C.
34
Advantages Of Low Level Languages

➢ Run more quickly


➢ Require less memory

35
High Level Languages
 A programming language
 uses words and symbols to make it relatively easy to read
and write a computer program by human.

 FORTRAN, COBOL, BASIC, Logo, Pascal, C, C++, Java,


Python and others.

 In a high-level language
 NO one-to-one correspondence between Instructions of HLL
to Machine Language.
 One statement in a HLL may correspond to many
microprocessor instructions.

36
Comparing ML/AL/HLL (Addition of Two numbers)

➢ For example, the machine code for adding two integers might be:
01000001 00111010 00111101
01000001 00101011 01000010
01000011 00111010
01000111 00111110

➢ While the assembly language code might be:


LOAD B 63 ; Initialize B with 63
LOAD A 66 ; Initialize B with 63 (Note: A is accumulator register)
ADD B ; Add the value of A with B and Store in A
STORE C ; Store the value of A in C

➢ High Level Language Program (Python language)


B = 63
A = 66
C=A+B
37
Advantages Of High Level Languages
➢ Reduce the number of instructions that must be
written.

➢ Allow programs to be written in a shorter amount of


time than a low-level language would take.

➢ Reduce the number of errors that are made because the


instructions are easier to remember.

➢ HLL programs are more portable.

38
Translation
➢ Source code: A program written in a high-level
language.

➢ Translation: The programs are translated into


machine language by interpreters or
compilers.

➢ Object Code: The resulting machine language


code.

39
Compilers
➢ A compiler makes the translation once so that the source code don’t
have to be translated each time the program is run.

➢ The source code is translated into a file called an object file.

➢A program called a linker is used to create an executable program.

➢ Most modern compilers let you compile and link in a single


operation, and have an “IDE” to enter text, debug, compile, link,
and run programs.

40
Interpreters
➢ An interpreter is a program that translates the source code of a
high-level language into machine language.

➢ It coverts each high-level program statement into the machine


code.

➢ Every time the program is run, the interpreter must translate each
instruction again.

41
Some Terminologies

42
Program v/s Process
Program v/s Process
 A program is a set of instructions written to complete the specific job on
your computer.
 For example, Google browser chrome.exe is an executable file which
stores a set of instructions written in it which allow you to view web
pages.
 Programs are never stored on the primary memory in your computer.
 Instead, they are stored on a disk or secondary memory.
Program v/s Process
 A process is an execution of any specific program.
 It is considered an active entity that performs the purpose of the
application.
 Multiple processes may be related to the same program.
 For example
 If you are double click on your Google Chrome browser icon on your PC
or laptop, you start a process which will run the Google Chrome
program.
 When you open another instance of Chrome, you are essentially
creating a two process.
Uni-Processor
 A computer system with a single central processing unit
that is known as uni-processor.

 The uni-processor can execute either single or multiple


program(s) simultaneously.
Multiprogramming

 Running Single Programs


 Suppose, there is one process in memory to execute (CPU task
or I/O task).
 If the process needs I/O units, It leads to Idle CPU.
Multiprogramming

 Running Multiple Programs


 In a multiprogramming system, more than one programs are
loaded in main memory which are ready to execute.
 Only one process at a time is able to get the CPU for
executing its instructions while all the others are waiting their
turn.
 The ultimate goal of multiprogramming is to keep the CPU
busy as long as there are processes ready to execute.

 Multiprogramming may lead to Thrashing


Multitasking

 If multiple programs/processes are running at the same


time.
 In multitasking, each running process takes only a fair
quantum of the CPU time.
 It ensures that any task does not hijack the CPU until it
finishes but rather a fair share amount of the CPU is given
to every program in main memory.
Multi-Processor
 Multiprocessing sometimes refers to executing multiple
processes (programs) at the same time.

 This might be misleading because of the term


“multiprogramming” .

 In fact, multiprocessing refers to the hardware (i.e.,


the CPU units) rather than the software (i.e., running
processes).

 Anyway, a system can be both multi-programmed by


having multiple programs running at the same time and
multiprocessing by having more than one physical
processor.
Top Level View of Computer
&
Program Execution

(Ref. - William Stallings)


Top Level View
• At a top level, a computer consists of
 CPU
 Memory
 I/O Module I/O Components Missing ?

 System Bus

• The above components are interconnected to achieve the basic


function of the computer-
 The basic function of a computer is to execute programs.
Top Level View

At top level, we can describe a computer system by

 Describing the external behaviour of each component—


 The data and control signals exchanged between all
components

 Describing the interconnection structure

 Describing the controls required to manage the use of the


interconnection structure.
Top Level View of Computer
Central Processing Unit (CPU)
➢ Also known as microprocessor: Housed on a tiny silicon chip

➢ Includes all binary circuits i.e. ALU, CU and Registers ---on a


single Integrated Chip (IC).

➢ Chip contains millions of switches and pathways that help your


computer make important decisions.

➢ Carries out the program’s instructions!


➢ Operates on data it finds in the computer’s memory.
Central Processing Unit (CPU)

➢ CPU has four key parts :

➢ Control Unit
➢ Arithmetic & Logic Unit
➢ Registers
➢ Clock
➢ And, of course, wires that connect everything
together.
Control unit
➢ It is the “boss” and coordinates all of the CPU’s activities.

➢ The circuitry that controls the flow of information through the processor, and
coordinates the activities of the other units within it.

➢ It controls sequence of operations.


➢ Uses programming instructions.

➢ In a way, it is the "brain within the brain", as it controls what happens inside
the processor, which in turn controls the rest of the system.
Control unit

➢ On a regular CPU, the control unit performs


➢ Fetching
➢ Decoding
➢ Managing execution
➢ Storing results.
Block Diagram of Control Unit
Arithmetic and logic unit (ALU)
➢ Circuitry to perform data manipulation.
➢ The component that performs operations.
➢ Performs arithmetic operations include addition,
subtractions, multiplication, division
➢ Performs the basic logical operations (AND, OR, NOT, XOR,
XNOR), and comparisons
➢ By combining arithmetic and logical operations-ALU performs
complex tasks.
Block Diagram of ALU
Register Set
➢ Temporary storage area to hold data applicable to the current
instruction/operation.

➢ Theregister set/array consists of circuitry used to temporarily


store data or program codes until they are sent to
➢ ALU
➢ memory
➢ Control section

➢ Numberof registers differs in different CPUs


➢ Some registers are common to all CPUs

➢ Measured by the number of bits they can hold


➢ "8-bit register" or a "32-bit register".
Register Set
➢ Program counter (PC)
➢ Accumulator(AC)
➢ Instruction Register (IR)
➢ Memory Address Register (MAR)
➢ Memory Buffer Register (MBR)
➢ I/O Address Register (I/O AR)
➢ I/O Buffer Register (I/O BR)
Program counter (PC)
➢A 16 bit register, used to store the address of the next
instruction to be fetched by the CPU.

➢ Thisregister maintains the sequential execution of a


program.
Accumulator
➢A register in which intermediate arithmetic and logic
results are stored.

➢Example –Use of accumulator in summation.


➢The accumulator is initially set to zero.
➢Then, each number in turn is added to the value in the
accumulator.
➢Only when all numbers have been added is the result held in
the accumulator written to main memory or to another, non-
accumulator (CPU register).
Register Set
➢ Instruction Register (IR)
➢ Holds last instruction fetched

➢ Memory Address Register (MAR)


➢ Connected to address bus and main memory
➢ Specifies address for read or write from main memory

➢ Memory Buffer Register (MBR)


➢ Connected to data bus and main memory
➢ Holds data to write or last data read
Register Set
➢ I/O Address Register (I/O AR)
➢ Connected to address bus and I/O module
➢ Specifies address for read or write from I/O module

➢ I/O Buffer Register (I/O BR)


➢ Connected to data bus and I/O module
➢ Holds data to write or last data read
Clock
 Triggers start and stop of all CPU operations. (heartbeat)

 Every computer contains an internal clock


 Regulates the rate at which instructions are executed
 Synchronizes all components

 The faster the clock, the more instructions the CPU can
execute per second.

 Clock speeds are expressed in megahertz (MHz) or


gigahertz ((GHz).
Top Level View of Computer
Memory
 A physical device capable of storing information temporarily or
permanently.

 Two Types
 Long term / Read Only Memory (ROM)/Non-volatile Memory
 It stores information permanently

 Short term Memory / Random Access Memory (RAM)/Volatile


Memory
 It stores information temporarily

Why do computer systems have different types of memories ?


70
Read Only Memory (ROM)
➢ A type of non-volatile memory used in computers/Other electronic devices.

➢ Read-only memory is useful for storing software that is rarely changed during
the life of the system, sometimes known as firmware.

➢ The computer can only read from a ROM chip.

➢ Data stored in ROM cannot be electronically modified after the manufacture


of the memory device.

➢ Most common is the BIOS ROM-


➢ The computer uses instructions contained on this chip to start the system
when you turn on the computer system.

71
Random Access Memory (RAM)
• Also known as the main memory/primary memory
• It can be used to read and changed in any order
• It is typically used to store working data/machine code
• It is volatile

• It allows data items to be read or written in almost the same amount


of time irrespective of the physical location of data inside the
memory. (Why RAM?)

72
Random Access Memory (RAM)
Two Types
• Static RAM (SRAM)
• Typically used for CPU cache

• Dynamic RAM (DRAM)


• Typically used for main memory

• What happens to data on main memory?


• The CPU can read from and write to RAM.
• The contents of main memory can be transferred to auxiliary storage
devices such as hard disks, floppy diskettes, zip disks, compact disks, or
USB flash disk or vice-versa.

73
Main Memory
 How memory is used?
 When a program such as your Internet Explorer(IE) is clicked
to open.
 The program of IE is loaded from your hard drive and placed
into RAM.
 The program now becomes process.
 This process now communicates with the processor at higher
speeds (than hard disk).

 Why memory is used ?


➢ It provides a place to quickly access or store data.
Top Level View of Computer
Communication of CPU with different Components

Communication
➢ Data and instructions need to get into the system and
results out
➢ Input/output

➢ Temporary storage for code and results is needed


➢ Main memory

➢ Temporary storage is required to hold data during data


processing.
➢ Registers

➢System bus is used to provide communication between


Main Memory, CPU and I/O module
Bus
➢ A communication pathway connecting two or more devices.
➢ Usually broadcast
➢ Serial or Parallel

➢ Often grouped
➢ A number of channels in one bus
➢ 32 bit data bus is 32 separate single bit channels
System Bus?
➢ A system bus is a composite bus that connects the
major components of a computer system.

➢ It combines three buses


➢ Address Bus: To determine where the data should
be sent/fetched

➢ Data Bus: Use to carry actual data

➢ Control Bus: What to do with this data (operation-


Read/Write)
Communication of CPU with different
Components

Address bus
ALU Register Set

Data bus

Control Unit and timing section

Control bus
Address bus
➢ Uni-directional Bus

➢ Identify the source or destination of actual data


➢ CPU reads an instruction (data) from a given location in memory
➢ CPU writes data to given location in memory

➢ The width of address bus determines maximum memory capacity of


system
➢ 8080 has 16 bit address bus giving 64k address space
➢ For n-bit address bus-2n addresses
Data Bus
➢ Bi-directional

➢ Carries actual data


➢ Remember that there is no difference between “data”
and “instruction” at this level

➢ The width of data bus is a key determinant of


performance
➢ 8, 16, 32, 64-bits
Control Bus
➢ Control and timing information
➢ Read/write signal
➢ Interrupt request
➢ Clock signals

➢ The control bus carries commands from the CPU and


returns status signals from the devices.

➢ Example, if the data is being read/written to the device


the appropriate line (read/write) will be active.
Top Level View of Computer
Input / Output Module
 I/O module provides an interface to control the
interaction with the outside world in an efficient
manner.

 I/O module consists of logic for performing a


communication between the peripheral device and the
bus.

 I/O module consists of multiple modules


 Each module interfaces to the system bus.
 Each module controls one or more peripheral devices.
Input / Output Module
Input / Output Module
 The I/O module has two major functions-
 Interface to CPU and memory via the system bus
 Interface to peripheral devices (Keyboard, Mouse,
Monitor etc.)
Basic Operational Concept
Basic Operational Concept
MONITOR

PROCESSOR

Storage
KEYBOARD
devices

PRINTER
88
Basic Operational Concept

 Input
 Process/Manipulate
 Output
 Storage

Input Process Output

Store Data 89
Basic Operational Concept
 The model executes instructions sequentially.
 To execute a program, the CPU “reads” each
instruction SEQUETIALLY and “executes” it.

 To execute any instruction, the CPU


 Fetcheseach instruction,
 Decodes it,
 Executes it.

 The sequence (Fetch-Decode-Execute) is followed for


all instructions.
90
Basic Operational Concept
 The model executes instructions sequentially.

 Fetch
 At the beginning of each instruction, the CPU presents the value
of the program counter on the address bus.
 The CPU then fetches the instruction from main memory via
the data bus into the instruction register.

 The program counter is then incremented to address the next


instruction in memory.

91
Basic Operational Concept
 Decode
 The data in instruction register is decoded by control unit.

 Execute
 The control unit sends a sequence of control signals to the
relevant functional units of the CPU to perform the actions
required by the instruction such as read/Write/Arithmetic
operation/others.

92
Top Level View of Computer
Program Execution
➢ In any program, all instructions are executed sequentially.

➢ To execute an instruction, following three cycles are used:


➢ Fetch
➢ Decode
➢ Execute
Fetch Cycle
➢Address of next instruction is in PC which is copied to MAR.

➢Address from MAR is placed on address bus

➢Control unit issues READ command

➢Result (data fetched from memory) copied/appears on data bus

➢Data from data bus copied into MBR

➢PC incremented by 1 (in parallel with data fetch from memory)

➢Data is moved from MBR to IR

➢MBR/MAR are now free for further data fetches


Decode Cycle
➢ The binary value in Instruction Register (IR) is
interpreted by Control Unit.
➢ It may be some instruction/data

➢ Each instruction consists of two parts


➢ Operation code
➢ Operands
Execute Cycle
Different for each instruction

➢ 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
Program Execution: An example
 Assumptions

 The word length in memory is 16-bits


 The words in memory are expressed in hexadecimal form.
 Each instruction is divided into opcode(4-bits) and operands (12-bits)

 Consider the list of op-codes


0001 (1h) – Load AC from memory
0010 (2h) – Store AC to memory
0101 (5h) – Add to AC from memory

 Program to execute
 Add two numbers stored at address 940h and 941h.
 Store the result at location 941h.
Program Execution: An example

1st
Instruction:
Fetch Cycle
Program Execution: An example

1st Instruction: Decode and Execute


 0001 (1h) - Load AC from memory

• 1940h - Load
Accumulator Register
from the value stored
at memory location
940
Program Execution: An example

2nd Instruction:
Fetch Cycle
Program Execution: An example

2nd Instruction:
Decode and Execute

 0101 (5h) - Add to AC


from memory

 5941h- Add to
Accumulator Register
the value stored at
memory location
941h
Program Execution: An example

3rd Instruction

Fetch Cycle
Program Execution: An example

3rd Instruction
-Decode and Execute

 0010
(2h) - Store AC to
memory

 2941h- Store the


value of Accumulator
Register at memory
location 941h
Program Execution: An example
Instruction Cycle State Diagram
INTERRUPTS
How interrupts are handled?
Interrupts
 Normally, the CPU start executing the list of instructions in one program and
keep running the instructions until
 EITHER it can't go any further
 OR an interrupt signal is sensed.

 An interrupt
 A signal from a device attached to a computer or from a program
within the computer
 Requires the operating system to stop and figure out what to do next.

 It is a mechanism by which other modules (e.g. I/O) may interrupt normal


sequence of processing.
Program Execution without and with Interrupt
Interrupt Cycle
➢ To handle interrupt, interrupt cycle is 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
Instruction Cycle with Interrupts
Transfer of Control via Interrupts
Benefits of Interrupt Handling
Benefits of Interrupt Handling
Short I/O Wait
Benefits of Interrupt Handling
Benefits of Interrupt Handling-Long I/O Wait
Instruction Cycle (with Interrupt stage)
State Diagram
Interrupts
 An operating system usually has some code that is called an interrupt
handler.

 The interrupt handler prioritizes the interrupts and saves them in


a queue if more than one is waiting to be handled.

 The operating system has another little program, sometimes called


a scheduler, that figures out which program to execute next.

 After occurrence of interrupt, the computer either


 Resumes running the current program or
 Begins running another program.
Interrupts
 Hardware interrupts
 Itoccurs when an I/O operation is completed such as
reading some data into the computer from a tape
drive.

 Software interrupts
 It occurs when an application program terminates
abruptly or requests certain services from the
operating system.
Interrupts
Multiple Interrupts
 Two approaches to deal with multiple interrupts
 Sequential or Disable interrupts
 Nested or Priority Based
Multiple Interrupts

 Sequential
 The processor can and will ignore that interrupt request signal
while processing one interrupt.
 Interrupts remain pending and are checked after current
interrupt has been processed.
 Interrupts handled in sequence as they occur.

 Disadvantage
 High priority or time-critical tasks may be ignored.
Multiple Interrupts- Sequential
Multiple Interrupts
 Nested
 Low priority interrupts can be interrupted by higher priority
interrupts
 When higher priority interrupt has been processed, processor
returns to previous interrupt
Multiple Interrupts – Nested
Time Sequence of Multiple Interrupts

Disk
interrupt
occurs at
t=20.
THANK YOU

Anda mungkin juga menyukai