7.4.1 Calling DOS and ROM-BIOS Interrupts

Interrupts are the only way to access DOS from assembly language. They are called with the INT instruction, which takes one operand—an immediate value between 0 and 255.

When calling DOS and ROM-BIOS interrupts, you usually need to place a function number in the AH register. You can use other registers to pass arguments to functions. Some interrupts and functions return values in certain registers, although register use varies for each interrupt. This code writes the text of msg to the screen.

.DATA

msg BYTE "This writes to the screen",$

.CODE

mov dx, offset msg

mov ah, 09h

int 21h

When the INT instruction executes, the processor takes the following six steps:

1.Looks up the address of the interrupt routine in the interrupt descriptor table (also called the “interrupt vector”). This table starts at the lowest point in memory (segment 0, offset 0) and consists of four bytes (two segment and two offset) for each interrupt. Thus, the address of an interrupt routine equals the number of the interrupt multiplied by 4.

2.Clears the trap flag (TF) and interrupt enable flag (IF).

3.Pushes the flags register, the current code segment (CS), and the current instruction pointer (IP).

4.Jumps to the address of the interrupt routine, as specified in the interrupt descriptor table.

5.Executes the code of the interrupt routine until it encounters an IRET instruction.

6.Pops the instruction pointer, code segment, and flags.

Figure 7.3 illustrates how interrupts work.

Some DOS interrupts should not normally be called. Some (such as 20h and 27h) have been replaced by other DOS interrupts. Others are used internally by DOS.