What is interrupt?
An interrupt interrupts the normal program flow, and transfers control from our program to Linux so that it will do a system call. Or in simple words,Interrupt is a mechanism by which a program’s flow control can be altered.You can think of it as like signaling Batman.You need something done, you send the signal, and then he comes to the rescue. You don’t care how he does his work.The most important thing to remember about an interrupt is that it can pause the execution of some program at any point between two instructions when an interrupt occurs. Therefore, you typically have no guarantee that one instruction always executes immediately after another in the program because an interrupt could occur between the two instructions.If an interrupt occurs in the middle of the execution of some instruction, then the CPU finishes that instruction before transferring control to the appropriate interrupt service routine.
In DOS assembly, most things get done with the DOS services interrupt int 21h, and the BIOS service interrupts like int 10h and int 16h. In Linux, all these functions are handled by the kernel. Everything gets done with "kernel system calls", and you call the kernel with int 80h.
The BIOS library is divided into a bunch of sections called interrupts. Each interrupt handled a different aspect of the computer--keyboard I/O, screen drawing functions, file and disk I/O, and so on. Each interrupt then had a whole bunch of functions, each given a number. They used AH (and if the interrupt had a lot of functions, AX) to determine which function to call. Arguments to the interrupts were passed in registers instead of on the stack to speed things up a bit.
Let's look at a simple interrupt call:
1. int 16h - BIOS Keyboard interrupt
ah=0 reads key from keyboard without echo
returns al=ascii, ah=scan code
ah=1 finds out if a key was hit
if no keys were pressed:
zf set (ie, jz NoKey)
ax=0
if a key was pressed:
zf clear (not set -> jnz KeyReady)
ah=scan code
al=ascii
2. int 21h - DOS functions
ah=1 reads key from keyboard with echo
returns al=ascii
ah=2 prints a character (dl=ascii)
returns nothing
ah=5 prints character to printer (dl=ascii)
returns nothing
ah=9 prints a string ending in $ (ds:dx=pointer to string)
returns nothing
ah=a buffered keyboard input (ds:dx=pointer to buffer)
The buffer is in this form:
1 byte The max number of characters to read (including enter)
1 byte The number of characters read (it gets filled in)
n bytes The buffer (n must be at least 1)
Enter (ascii 13: carriage return) is also stored.
ah=4c Exit the program (al=error code)
3. int 10h - BIOS Video interrupt
ah=0 set video mode (al=3 -> text, al=12h,13h -> vga)
returns nothing
ah=2 set cursor position (bh=0, dh=row, dl=column)
dh and dl are zero-based
returns nothing
ah=c display graphics pixel (al=color, bh=0, cx=column, dx=row)
cx and dx are zero-based
returns nothing
4. int 19h - Bootstrap loader: Will reboot your computer to the drive specified in dl.Some computers warm boot, some cold boot, and others do nothing register ah doesn't matter here.
An interrupt interrupts the normal program flow, and transfers control from our program to Linux so that it will do a system call. Or in simple words,Interrupt is a mechanism by which a program’s flow control can be altered.You can think of it as like signaling Batman.You need something done, you send the signal, and then he comes to the rescue. You don’t care how he does his work.The most important thing to remember about an interrupt is that it can pause the execution of some program at any point between two instructions when an interrupt occurs. Therefore, you typically have no guarantee that one instruction always executes immediately after another in the program because an interrupt could occur between the two instructions.If an interrupt occurs in the middle of the execution of some instruction, then the CPU finishes that instruction before transferring control to the appropriate interrupt service routine.
In DOS assembly, most things get done with the DOS services interrupt int 21h, and the BIOS service interrupts like int 10h and int 16h. In Linux, all these functions are handled by the kernel. Everything gets done with "kernel system calls", and you call the kernel with int 80h.
The BIOS library is divided into a bunch of sections called interrupts. Each interrupt handled a different aspect of the computer--keyboard I/O, screen drawing functions, file and disk I/O, and so on. Each interrupt then had a whole bunch of functions, each given a number. They used AH (and if the interrupt had a lot of functions, AX) to determine which function to call. Arguments to the interrupts were passed in registers instead of on the stack to speed things up a bit.
Let's look at a simple interrupt call:
1. int 16h - BIOS Keyboard interrupt
ah=0 reads key from keyboard without echo
returns al=ascii, ah=scan code
ah=1 finds out if a key was hit
if no keys were pressed:
zf set (ie, jz NoKey)
ax=0
if a key was pressed:
zf clear (not set -> jnz KeyReady)
ah=scan code
al=ascii
2. int 21h - DOS functions
ah=1 reads key from keyboard with echo
returns al=ascii
ah=2 prints a character (dl=ascii)
returns nothing
ah=5 prints character to printer (dl=ascii)
returns nothing
ah=9 prints a string ending in $ (ds:dx=pointer to string)
returns nothing
ah=a buffered keyboard input (ds:dx=pointer to buffer)
The buffer is in this form:
1 byte The max number of characters to read (including enter)
1 byte The number of characters read (it gets filled in)
n bytes The buffer (n must be at least 1)
Enter (ascii 13: carriage return) is also stored.
ah=4c Exit the program (al=error code)
3. int 10h - BIOS Video interrupt
ah=0 set video mode (al=3 -> text, al=12h,13h -> vga)
returns nothing
ah=2 set cursor position (bh=0, dh=row, dl=column)
dh and dl are zero-based
returns nothing
ah=c display graphics pixel (al=color, bh=0, cx=column, dx=row)
cx and dx are zero-based
returns nothing
4. int 19h - Bootstrap loader: Will reboot your computer to the drive specified in dl.Some computers warm boot, some cold boot, and others do nothing register ah doesn't matter here.
If you like this post or have any question, please feel free to comment!