Professional Documents
Culture Documents
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.
• 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.
• 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.
• 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 $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
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
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
8 32 bits of data
12 32 bits of data
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
H.Corporaal 5MD00 19
Intel Processors Timelinesee intel museum:
www.intel.com/museum/online/hist_micro/hof
• 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.
H.Corporaal 5MD00 22
C program
Starting a program
compiler
Assembly program
assembler
Executable
loader
Memory
H.Corporaal 5MD00 23