You are on page 1of 23

Computer Architecture

Lecture 7
Topics in this Lecture
• Interrupt
• Hardware Interrupts
• Software Interrupts
• Interrupt Handling
• Interrupts in Intel 8086
• Polling
• Types of Polling
• Main Types of Instructions in MIPS
• MIPS arithmetic
• Branches and Jumps in MIPS
Interrupt
• An interrupt is a signal from a device attached to a computer or from a program within the
computer that requires the operating system to stop and figure out what to do next. 
• Basically, a single computer can perform only one computer instruction at a time. But,
because it can be interrupted, it can take turns in which programs or sets of instructions that
it performs. This is known as multitasking.
• 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. Queues can use different algorithms such as First Come First Serve,
Round Robin etc.
• The operating system has another little program, sometimes called a scheduler, that figures
out which program to give control to next. Types of Schedulers are Short Term Scheduler,
Long Term Scheduler and Medium Term Scheduler.
Hardware Interrupts
What is an Interrupt?
Interrupt is a signal which has highest priority from hardware or software that processor should
process it immediately.
Types of Interrupts:
• 1. Hardware Interrupts: If the signal for the processor is from external device or hardware, it
is called hardware interrupt. Example: from keyboard we will press the key to do some action
this pressing of key in keyboard will generate a signal which is given to the processor to do
action, such interrupts are called hardware interrupts. Hardware interrupts can be classified
into two types they are:

• Maskable Interrupt: The hardware interrupts which can be delayed when a much highest
priority interrupt has occurred to the processor.
• Non Maskable Interrupt: The hardware which cannot be delayed and should process by the
processor immediately .
Software Interrupts
Software Interrupts: : The interrupts which are caused by the software instructions are called software interrupts.
Software interrupt can also divided in to two types. They are:

• Normal Interrupts: the interrupts which are caused by the software instructions that change CPU’s current
code of execution without causing any error or exception.

• Exception: unplanned interrupts while executing a program is called Exception. For example: while executing a
program if we got a value which should be divided by zero is called a exception.

Classification of Interrupts According to Periodicity of Occurrence:


• 1. Periodic Interrupt: If the interrupts occurred at fixed interval in timeline then that interrupts are called
periodic interrupts.
• 2. Aperiodic Interrupt: If the occurrence of interrupt cannot be predicted then that interrupt is called
aperiodic interrupt.

Classification of Interrupts According to the Temporal Relationship with System Clock:


• 1. Synchronous Interrupt: The source of interrupt is in phase to the system clock is called synchronous
interrupt. In other words interrupts which are dependent on the system clock. Example: timer service that
uses the system clock.
• 2. Asynchronous Interrupts: If the interrupts are independent or not in phase to the system clock is called
asynchronous interrupt.
Interrupt Handling
• Type of Interrupt Handlers:
• First-Level Interrupt Handler (FLIH)
• Second-Level Interrupt Handlers (SLIH)
• FLIHs are also known as hard interrupt handlers or fast interrupt handlers.
• SLIHs are also known as slow/soft interrupt handlers, or Deferred Procedure Calls in
Windows. 

• Interrupt Latency:
• When an interrupt occur, the service of the interrupt by executing the ISR may not start
immediately by context switching. The time interval between the occurrence of interrupt and
start of execution of the ISR is called interrupt latency.
• How to calculate Interrupt Latency?
• Tswitch = Time taken for context switch
• ΣTexec = The sum of time interval for executing the ISR
• Interrupt Latency = Tswitch + ΣTexec
Interrupts in the Intel 8086

Hardware Interrupts
Hardware interrupt is caused by any peripheral device by
sending a signal through a specified pin to the microprocessor.

The 8086 has two hardware interrupt pins, i.e. NMI and INTR:
•NMI is a non-maskable interrupt
•INTR is a maskable interrupt having lower priority.

One more interrupt pin associated is INTA called interrupt


acknowledge.
Polling
• Polling: OS periodically/synchronously queries each device to see if new
information is available.

• OS periodically asks (polls) each device for event information.


• If an event has occurred, OS retrieves event information (keyboard keys
pressed) from hardware.
• Each device must wait for Polling Interval.
• Shortening Polling Interval leads to inefficiency.

• Interrupt VS Polling
• Interrupt is an Asynchronous Method to handle requests
• Polling is Synchronous Method to handle requests
Types of Polling
• A polling cycle is the time in which each element is monitored once. The optimal polling cycle
will vary according to several factors, including the response time and the overhead (e.g.,
processor time and bandwidth) of the polling.

• In roll call polling, the polling device or process queries each element on a list in a fixed
sequence. Because it waits for a response from each element, a timing mechanism is
necessary to prevent lock-ups caused by non-responding elements.

• In hub polling, also referred to as token polling, each element polls the next element in some
fixed sequence. This continues until the first element is reached, at which time the polling
cycle starts all over again.

• A poll message is a control-acknowledgment message.


Main Types of Instructions in MIPS
• Arithmetic
– Integer
– Floating Point

• Memory access instructions


– Load & Store

• Control flow
– Jump
– Conditional Branch
– Call & Return

H.Corporaal 5MD00 10
MIPS arithmetic
• Most instructions have 3 operands
• Operand order is fixed (destination first)

Example:

C code: A = B + C

MIPS code: add $s0, $s1, $s2

($s0, $s1 and $s2 are associated with variables by


compiler)
H.Corporaal 5MD00 11
MIPS arithmetic
C code: A = B + C + D;
E = F - A;

MIPS code: add $t0, $s1, $s2 //$s1=B and $s2=C and $t0=temp variable
add $s0, $t0, $s3 //$s3=D and $s0=A
sub $s4, $s5, $s0 //$s4=E and $s5=F and $s0=A

• Operands must be registers, only 32 registers provided


• Design Principle: smaller is faster.

H.Corporaal 5MD00 12
Branches and Jumps in MIPS
• Instructions:
bne $t4,$t5,Label Next instruction is at Label if $t4  $t5
beq $t4,$t5,Label Next instruction is at Label if $t4 = $t5
j Label Next instruction is at Label

H.Corporaal 5MD00 13
Register allocation
• Compiler tries to keep as many variables in registers as
possible

• Some variables can not be allocated:


– large arrays (too few registers)
– aliased variables (variables accessible through pointers in C)
– dynamic allocated variables
• heap
• stack

• Compiler may run out of registers => spilling


H.Corporaal 5MD00 14
Memory Organization
• Viewed as a large, single-dimension array, with an address.
• A memory address is an index location in the array.
• "Byte addressing" means that successive addresses are one
byte apart.

0 8 bits of data

1 8 bits of data

2 8 bits of data

3 8 bits of data

4 8 bits of data

5 8 bits of data

6 8 bits of data

...
H.Corporaal 5MD00 15
Memory Organization
• Bytes are nice, but most data items use larger "words"
• For MIPS, a word is 32 bits or 4 bytes.
0 32 bits of data

4 32 bits of data Registers hold 32 bits of data

8 32 bits of data

12 32 bits of data

• 232 bytes with byte addresses from 0 to 232-1


• 232 words with byte addresses 0, 4, 8, ... 232-4

H.Corporaal 5MD00 16
Memory layout: Alignment
31 23 15 7 0
0 this word is aligned; the others are not!
4

8
address

12

16

20

24

H.Corporaal 5MD00 17
Assembly Language vs. Machine Language

• Assembly language is a more human readable view of machine language.


Instead of representing the machine language as numbers, the
instructions and registers are given names (typically abbreviated words, or
mnemonics, eg ld means "load").

• Assembly Language is a Low Level Language.

• Each assembly language is specific to a particular computer architecture


and operating system. In contrast, most high-level programming
languages are generally portable across multiple architectures but
require interpreting or compiling.

• Assembly code is converted into executable machine code by a utility


program referred to as an assembler. The conversion process is referred to
as assembly, or assembling the source code.
Assembly Language vs. Machine Language
• Assembly provides convenient symbolic representation
– much easier than writing down numbers
– e.g., destination first
• Machine language is the underlying reality

• Assembly can provide 'pseudoinstructions'


– e.g., “move $t0, $t1” exists only in Assembly

• When considering performance you should count real


instructions

H.Corporaal 5MD00 19
Intel Processors Timelinesee intel museum:
www.intel.com/museum/online/hist_micro/hof

• 1978: The Intel 8086 is announced (16 bit architecture)


• 1980: The 8087 floating point coprocessor is added
• 1982: The 80286 increases address space to 24 bits, +instructions
• 1985: The 80386 extends to 32 bits, new addressing modes
• 1989-1995: The 80486, Pentium, Pentium Pro add a few instructions
(mostly designed for higher performance)
• 1997: Pentium II with MMX is added
• 1999: Pentium III, with 70 more SIMD instructions
• 2001: Pentium IV, very deep pipeline (20 stages) results in high freq.
• 2003: Pentium IV – Hyperthreading
• 2005: Multi-core solutions
• 2008: Low power ATOM: about 1 Watt
• 2009: Lincroft: integrated graphics

Note: AMD has competitive processors


H.Corporaal 5MD00 20
A dominant architecture: 80x86
• Complexity:
– Instructions from 1 to 17 bytes long
– one operand must act as both a source and
destination
– one operand can come from memory
– complex addressing modes

• Saving grace:
– the most frequently used instructions are not too
difficult to build
H.Corporaal 5MD00 21
Starting a program
• Compile a C program

• Link
– insert library code e.g., iostream.h, conio.h etc.

• Load into memory


– load text (code)
– load data (global data)
– copy parameters to the main program onto the stack
– jump to ‘start-up’ routine
• call main

H.Corporaal 5MD00 22
C program
Starting a program
compiler

Assembly program

assembler

Executable

loader

Memory

H.Corporaal 5MD00 23

You might also like