3.3 Real Mode
16-bit executable is doing when it runs. You can use debug.exe to view the
state of the real-mode execution environment via the register command:
C:\>debug MyProgram.com
- 1
AX=0000 BX=0000
CX=0000 DX=
0000 SP=
FFEE
BP=0000 SI=0000 DI=0000
DS=1779 ES=1779
SS=1779 CS =
1779 IP=
0100
NV UP EI NG NZ NA PO NC
1779:0100 0000
ADD
[BX+SI]
.AL
The r command dumps Ihe contents of the registers follovi�ed by the current
instruction being pointed to by the IP register. The string "NV UP EI NG NZ NA
PO NC" represents 8 bits of the FLAGS register, excluding the TF. If the IF is
set, you'll see the EI (enable interrupts) characters in the flag string. Other¬
wise you'll see Di (disable interrupts).
Real-Mode Interrupts
In the most general sense, an interrupt \s some event that triggers the execu¬
tion of a special type of procedure called an interrupt service routine (ISR),
also knov�n as an interrupt handler. Each specific type of event is assigned
an integer value that associates each event type with the appropriate ISR. The
specific details of how interrupts are handled vary, depending on whether the
processor is in real mode or protected mode.
In real mode, the first kilobyte of memory (address OxOOOOO to 0x003FF) is
occupied by a special data structure called the interrupt vector table (IVT).
In protected mode, this structure is callcd the interrupt descriptor table (IDT),
but the basic purpose is the same. The IVT and IDT both map interrupts
to the ISRs that handle them. Specifically, they store a series of interrupt
descriptors (called interrupt vectors in real mode) that designate where to
locate the ISRs in memory.
In real mode, the IVT does this by storing the logical address of each ISR
sequentially (see Figure 3.7). At the bottom of memory (address OxOOOOO) is
the effective address of the first ISR followed by its segment selector. Note
that for both values, the low byte of the address comes first. This is the inter¬
rupt vector for interrupt type 0. The next four bytes of memory (0x00004 to
0x00007) store the interrupt vector for interrupt type 1, and so on. Because
each interrupt takes 4 bytes, the IVT can hold 256 vectors (designated by
values 0 to 255). When an interrupt occurs in real mode, the processor uses
the address stored in the corresponding interrupt vector to locate and execute
the necessary procedure.
Parti I 67