0% found this document useful (0 votes)
19 views11 pages

6-4 Intro To Interrupts: An Interrupt Is A Hardware-Generated CALL or A Software-Generated CALL

Uploaded by

joselazaro.2037
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views11 pages

6-4 Intro To Interrupts: An Interrupt Is A Hardware-Generated CALL or A Software-Generated CALL

Uploaded by

joselazaro.2037
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Chapter 6: Program Control Instructions

6–4 INTRO TO INTERRUPTS


• An interrupt is a hardware-generated CALL
– externally derived from a hardware signal
• Or a software-generated CALL
– internally derived from the execution of an
instruction or by some other internal event
– at times an internal interrupt is called an exception
• Either type interrupts the program by calling
an interrupt service procedure (ISP) or
interrupt handler.

The Intel Microprocessors: 8086/8088, 80186/80188, 80286, 80386, 80486 Pentium,


Pentium Pro Processor, Pentium II, Pentium, 4, and Core2 with 64-bit Extensions Copyright ©2009 by Pearson Education, Inc.
Architecture, Programming, and Interfacing, Eighth Edition Upper Saddle River, New Jersey 07458 • All rights reserved.
Barry B. Brey

١
Interrupt Vectors
• A 4-byte number stored in the first 1024 bytes
of memory (00000H–003FFH) in real mode.
– in protected mode, the vector table is replaced by
an interrupt descriptor table that uses 8-byte
descriptors to describe each of the interrupts
• 256 different interrupt vectors.
– each vector contains the address of an interrupt
service procedure

The Intel Microprocessors: 8086/8088, 80186/80188, 80286, 80386, 80486 Pentium,


Pentium Pro Processor, Pentium II, Pentium, 4, and Core2 with 64-bit Extensions Copyright ©2009 by Pearson Education, Inc.
Architecture, Programming, and Interfacing, Eighth Edition Upper Saddle River, New Jersey 07458 • All rights reserved.
Barry B. Brey

• Each vector contains a value for IP and CS


that forms the address of the interrupt service
procedure.
– the first 2 bytes contain IP; the last 2 bytes CS

• Some reserved vectors are for errors that


occur during the execution of software
– such as the divide error interrupt

The Intel Microprocessors: 8086/8088, 80186/80188, 80286, 80386, 80486 Pentium,


Pentium Pro Processor, Pentium II, Pentium, 4, and Core2 with 64-bit Extensions Copyright ©2009 by Pearson Education, Inc.
Architecture, Programming, and Interfacing, Eighth Edition Upper Saddle River, New Jersey 07458 • All rights reserved.
Barry B. Brey

٢
Interrupt Vectoring Process
Interrupt Handler
Calling program

mov... F000:F065 sti 3


int 10h F066 cld
add... F067 push es
1 2 F068 .
. .
. IRET

3069 F000:F065 F000:AB62


(entry for INT 10)

Interrupt Vector Table


4

The Intel Microprocessors: 8086/8088, 80186/80188, 80286, 80386, 80486 Pentium,


Pentium Pro Processor, Pentium II, Pentium, 4, and Core2 with 64-bit Extensions Copyright ©2009 by Pearson Education, Inc.
Architecture, Programming, and Interfacing, Eighth Edition Upper Saddle River, New Jersey 07458 • All rights reserved.
Barry B. Brey

Interrupt Instructions
• Three different interrupt instructions available:
– INT, INTO, and INT 3
• In real mode, each fetches a vector from the
vector table, and then calls the procedure
stored at the location addressed by the vector.
• In protected mode, each fetches an interrupt
descriptor from the interrupt descriptor table.
• Similar to a far CALL instruction because it
places the return address (IP/EIP and CS)
on the stack.
The Intel Microprocessors: 8086/8088, 80186/80188, 80286, 80386, 80486 Pentium,
Pentium Pro Processor, Pentium II, Pentium, 4, and Core2 with 64-bit Extensions Copyright ©2009 by Pearson Education, Inc.
Architecture, Programming, and Interfacing, Eighth Edition Upper Saddle River, New Jersey 07458 • All rights reserved.
Barry B. Brey

٣
INTs

• 256 different software interrupt instructions


(INTs) available to the programmer.
– each INT instruction has a numeric operand
whose range is 0 to 255 (00H–FFH)
• For example, INT 100 uses interrupt vector
100.

The Intel Microprocessors: 8086/8088, 80186/80188, 80286, 80386, 80486 Pentium,


Pentium Pro Processor, Pentium II, Pentium, 4, and Core2 with 64-bit Extensions Copyright ©2009 by Pearson Education, Inc.
Architecture, Programming, and Interfacing, Eighth Edition Upper Saddle River, New Jersey 07458 • All rights reserved.
Barry B. Brey

• Address of the interrupt vector is determined


by multiplying the interrupt type number by 4.
– INT 10H instruction calls the interrupt service
procedure whose address is stored beginning at
memory location 40H (10H  4) in the mode
• In protected mode, the interrupt descriptor is
located by multiplying the type number by 8
– because each descriptor is 8 bytes long
• Each INT instruction is 2 bytes long.
– the first byte contains the opcode
– the second byte contains the vector type number
The Intel Microprocessors: 8086/8088, 80186/80188, 80286, 80386, 80486 Pentium,
Pentium Pro Processor, Pentium II, Pentium, 4, and Core2 with 64-bit Extensions Copyright ©2009 by Pearson Education, Inc.
Architecture, Programming, and Interfacing, Eighth Edition Upper Saddle River, New Jersey 07458 • All rights reserved.
Barry B. Brey

٤
• When a software interrupt executes, it:
– pushes the flags onto the stack
– clears the T and I flag bits
– pushes CS onto the stack
– fetches the new value for CS from the
interrupt vector
– pushes IP/EIP onto the stack
– fetches the new value for IP/EIP from
the vector
– jumps to the new location addressed by
CS and IP/EIP

The Intel Microprocessors: 8086/8088, 80186/80188, 80286, 80386, 80486 Pentium,


Pentium Pro Processor, Pentium II, Pentium, 4, and Core2 with 64-bit Extensions Copyright ©2009 by Pearson Education, Inc.
Architecture, Programming, and Interfacing, Eighth Edition Upper Saddle River, New Jersey 07458 • All rights reserved.
Barry B. Brey

• INT performs as CALL


– not only pushes CS & IP onto the stack, also
pushes the flags onto the stack
• Software interrupts are most commonly used
to call system procedures because the
address of the function need not be known.
• The interrupts often control printers, video
displays, and disk drives.

The Intel Microprocessors: 8086/8088, 80186/80188, 80286, 80386, 80486 Pentium,


Pentium Pro Processor, Pentium II, Pentium, 4, and Core2 with 64-bit Extensions Copyright ©2009 by Pearson Education, Inc.
Architecture, Programming, and Interfacing, Eighth Edition Upper Saddle River, New Jersey 07458 • All rights reserved.
Barry B. Brey

٥
Common Interrupts
Software interrupts will call interrupt service
routines (ISRs) either in BIOS or DOS
• INT 10h Video Services
• INT 16h Keyboard Services
• INT 17h Printer Services
• INT 1Ah Time of Day
• INT 1Ch User Timer Interrupt
• INT 21h MS-DOS Services
The Intel Microprocessors: 8086/8088, 80186/80188, 80286, 80386, 80486 Pentium,
Pentium Pro Processor, Pentium II, Pentium, 4, and Core2 with 64-bit Extensions Copyright ©2009 by Pearson Education, Inc.
Architecture, Programming, and Interfacing, Eighth Edition Upper Saddle River, New Jersey 07458 • All rights reserved.
Barry B. Brey

Function 4Ch of INT 21h


• Terminate process:
– Ends the current process (program), returns an
optional 8-bit return code to the calling process.
– A return code of 0 usually indicates successful
completion.
mov ah,4Ch ; terminate process
mov al,0 ; return code
int 21h

The Intel Microprocessors: 8086/8088, 80186/80188, 80286, 80386, 80486 Pentium,


Pentium Pro Processor, Pentium II, Pentium, 4, and Core2 with 64-bit Extensions Copyright ©2009 by Pearson Education, Inc.
Architecture, Programming, and Interfacing, Eighth Edition Upper Saddle River, New Jersey 07458 • All rights reserved.
Barry B. Brey

٦
Function 09h of INT 21h
• INT 21h: invoke MS-DOS services
– Function code in AH, e.g. 09H = write string
– The string must be terminated by a '$' character.
– DS must point to the string's segment, and DX
must contain the string's offset.

mov ah,9
mov dx,OFFSET string
int 21h
string DB ‘Hello, World!$’

The Intel Microprocessors: 8086/8088, 80186/80188, 80286, 80386, 80486 Pentium,


Pentium Pro Processor, Pentium II, Pentium, 4, and Core2 with 64-bit Extensions Copyright ©2009 by Pearson Education, Inc.
Architecture, Programming, and Interfacing, Eighth Edition Upper Saddle River, New Jersey 07458 • All rights reserved.
Barry B. Brey

Selected I/O Functions


• Output functions:
– 02h, 06h - Write character to standard output
– 05h - Write character to default printer
– 09h - Write string to standard output
– 40h - Write string to file or device
• Input functions:
– 01h, 06h - Read character from standard input
– 0Ah - Read array of buffered characters from standard
input
– 0Bh - Get status of the standard input buffer
– 3Fh - Read from file or device

The Intel Microprocessors: 8086/8088, 80186/80188, 80286, 80386, 80486 Pentium,


Pentium Pro Processor, Pentium II, Pentium, 4, and Core2 with 64-bit Extensions Copyright ©2009 by Pearson Education, Inc.
Architecture, Programming, and Interfacing, Eighth Edition Upper Saddle River, New Jersey 07458 • All rights reserved.
Barry B. Brey

٧
IRET/IRETD
• Used only with software or hardware interrupt
service procedures.
• IRET is used in real mode and IRETD in the
protected mode.
• IRET instruction will
– pop stack data back into the IP
– pop stack data back into CS
– pop stack data back into the flag register
• Accomplishes the same tasks as the POPF
followed by a far RET instruction.
The Intel Microprocessors: 8086/8088, 80186/80188, 80286, 80386, 80486 Pentium,
Pentium Pro Processor, Pentium II, Pentium, 4, and Core2 with 64-bit Extensions Copyright ©2009 by Pearson Education, Inc.
Architecture, Programming, and Interfacing, Eighth Edition Upper Saddle River, New Jersey 07458 • All rights reserved.
Barry B. Brey

INT 3
• A special software interrupt designed to
function as a breakpoint.
– a 1-byte instruction, while others are 2-byte
• Common to insert an INT 3 in software to
interrupt or break the flow of the software.
– function is called a breakpoint
– breakpoints help to debug faulty software
• A breakpoint occurs for any software interrupt,
but because INT 3 is 1 byte long, it is easier to
use for this function.
The Intel Microprocessors: 8086/8088, 80186/80188, 80286, 80386, 80486 Pentium,
Pentium Pro Processor, Pentium II, Pentium, 4, and Core2 with 64-bit Extensions Copyright ©2009 by Pearson Education, Inc.
Architecture, Programming, and Interfacing, Eighth Edition Upper Saddle River, New Jersey 07458 • All rights reserved.
Barry B. Brey

٨
INTO
• Interrupt on overflow (INTO) is a conditional
software interrupt that tests overflow flag (O).
– If O = 0, INTO performs no operation
– if O = 1 and an INTO executes, an interrupt
occurs via vector type number 4
• The INTO instruction appears in software that
adds or subtracts signed binary numbers.
• JO or INTO instructions detect the overflow.

The Intel Microprocessors: 8086/8088, 80186/80188, 80286, 80386, 80486 Pentium,


Pentium Pro Processor, Pentium II, Pentium, 4, and Core2 with 64-bit Extensions Copyright ©2009 by Pearson Education, Inc.
Architecture, Programming, and Interfacing, Eighth Edition Upper Saddle River, New Jersey 07458 • All rights reserved.
Barry B. Brey

Interrupt Control
• Two instructions control the INTR pin.
• The set interrupt flag instruction (STI) places
1 in the I flag bit.
– which enables the INTR pin
• The clear interrupt flag instruction (CLI)
places a 0 into the I flag bit.
– which disables the INTR pin
• The STI instruction enables INTR and the CLI
instruction disables INTR.
The Intel Microprocessors: 8086/8088, 80186/80188, 80286, 80386, 80486 Pentium,
Pentium Pro Processor, Pentium II, Pentium, 4, and Core2 with 64-bit Extensions Copyright ©2009 by Pearson Education, Inc.
Architecture, Programming, and Interfacing, Eighth Edition Upper Saddle River, New Jersey 07458 • All rights reserved.
Barry B. Brey

٩
6–5 MACHINE CONTROL AND
MISCELLANEOUS INSTRUCTIONS
• These instructions provide control and perform
various other functions.

The Intel Microprocessors: 8086/8088, 80186/80188, 80286, 80386, 80486 Pentium,


Pentium Pro Processor, Pentium II, Pentium, 4, and Core2 with 64-bit Extensions Copyright ©2009 by Pearson Education, Inc.
Architecture, Programming, and Interfacing, Eighth Edition Upper Saddle River, New Jersey 07458 • All rights reserved.
Barry B. Brey

HLT
• Stops the execution of software.
• DOS and Windows both use interrupts
extensively.
– so HLT will not halt the computer when
operated under these operating systems

The Intel Microprocessors: 8086/8088, 80186/80188, 80286, 80386, 80486 Pentium,


Pentium Pro Processor, Pentium II, Pentium, 4, and Core2 with 64-bit Extensions Copyright ©2009 by Pearson Education, Inc.
Architecture, Programming, and Interfacing, Eighth Edition Upper Saddle River, New Jersey 07458 • All rights reserved.
Barry B. Brey

١٠
NOP
• In early years, before software development
tools were available, a NOP, which performs
absolutely no operation, was often used to pad
software with space for future machine
language instructions.
• When the microprocessor encounters a NOP,
it takes a short time to execute.

The Intel Microprocessors: 8086/8088, 80186/80188, 80286, 80386, 80486 Pentium,


Pentium Pro Processor, Pentium II, Pentium, 4, and Core2 with 64-bit Extensions Copyright ©2009 by Pearson Education, Inc.
Architecture, Programming, and Interfacing, Eighth Edition Upper Saddle River, New Jersey 07458 • All rights reserved.
Barry B. Brey

• If you are developing machine language


programs, which are extremely rare, it is
recommended that you place 10 or so NOPS
in your program at 50-byte intervals.
– in case you need to add instructions at some
future point
• A NOP may also find application in time
delays to waste time.
• A NOP used for timing is not very accurate.

The Intel Microprocessors: 8086/8088, 80186/80188, 80286, 80386, 80486 Pentium,


Pentium Pro Processor, Pentium II, Pentium, 4, and Core2 with 64-bit Extensions Copyright ©2009 by Pearson Education, Inc.
Architecture, Programming, and Interfacing, Eighth Edition Upper Saddle River, New Jersey 07458 • All rights reserved.
Barry B. Brey

١١

You might also like