Docsity

Interrupt Handling in Assembly Language Programming: A Detailed Guide, Lecture notes of Assembly Language Programming

Toggle sidebar
bg1
Computer Architecture & Assembly Language
Programming
Course Code: CS401
Virtual University of Pakistan 98
which informs about fatal hardware failures in the system and is tied
to interrupt 2. INT pin can be masked but NMI cannot be masked.
INT 3, Debug Interrupt
The only special thing about this interrupt is that it has a single byte
opcode and not a two byte combination where the second byte tells the
interrupt number. This allows it to replace any instruction whatsoever.
It is also used by the debugger and will be discussed in detail with the
debugger working.
INT 4, Arithmetic Overflow, change of sign bit
The overflow flag is set if the sign bit unexpectedly changes as a result
of a mathematical or logical instruction. However the overflow flag
signals a real overflow only if the numbers in question are treated as
signed numbers. So this interrupt is not automatically generated but
as a result of a special instruction INTO (interrupt on overflow) if the
overflow flag is set. Otherwise the INTO instruction behaves like a NOP
(no operation).
These are the five interrupts reserved by Intel and are generally not used in
our operations.
8.2. HOOKING AN INTERRUPT
To hook an interrupt we change the vector corresponding to that interrupt.
As soon as the interrupt vector changes, that interrupt will be routed to the
new handler. Our first example is with the divide by zero interrupt. The
normal system defined behavior in response to divide by zero is to display an
error message and terminate the program. We will change it to display our
own message.
Example 8.1
001
002
003
004
005
006
007-029
030-049
050-090
091
092
093
094
095
096
097
098
099
100
101
102
103
104
105
106
107
108
109
110
111
112
pf2

Partial preview of the text

Download Interrupt Handling in Assembly Language Programming: A Detailed Guide and more Lecture notes Assembly Language Programming in PDF only on Docsity!

Computer Architecture & Assembly Language

Programming

Course Code: CS

[email protected]

Virtual University of Pakistan 98

which informs about fatal hardware failures in the system and is tied

to interrupt 2. INT pin can be masked but NMI cannot be masked.

INT 3, Debug Interrupt

The only special thing about this interrupt is that it has a single byte

opcode and not a two byte combination where the second byte tells the

interrupt number. This allows it to replace any instruction whatsoever.

It is also used by the debugger and will be discussed in detail with the

debugger working.

INT 4, Arithmetic Overflow, change of sign bit

The overflow flag is set if the sign bit unexpectedly changes as a result

of a mathematical or logical instruction. However the overflow flag

signals a real overflow only if the numbers in question are treated as

signed numbers. So this interrupt is not automatically generated but

as a result of a special instruction INTO (interrupt on overflow) if the

overflow flag is set. Otherwise the INTO instruction behaves like a NOP

(no operation).

These are the five interrupts reserved by Intel and are generally not used in

our operations.

8.2. HOOKING AN INTERRUPT

To hook an interrupt we change the vector corresponding to that interrupt.

As soon as the interrupt vector changes, that interrupt will be routed to the

new handler. Our first example is with the divide by zero interrupt. The

normal system defined behavior in response to divide by zero is to display an

error message and terminate the program. We will change it to display our

own message.

Example 8.

; hooking divide by zero interrupt [org 0x0100] jmp start message: db 'You divided something by zero.', 0 ;;;;; COPY LINES 028-050 FROM EXAMPLE 7.4 (strlen) ;;;;; ;;;;; COPY LINES 005-024 FROM EXAMPLE 7.1 (clrscr) ;;;;; ;;;;; COPY LINES 050-090 FROM EXAMPLE 7.4 (printstr) ;;;;; ; divide by zero interrupt handler myisrfor0: push ax ; push all regs push bx push cx push dx push si push di push bp push ds push es push cs pop ds ; point ds to our data segment pop es pop ds

call clrscr ; clear the screen mov ax, 30 push ax ; push x position mov ax, 20 push ax ; push y position mov ax, 0x71 ; white on blue attribute push ax ; push attribute mov ax, message push ax ; push offset of message call printstr ; print message