ID: Q48444
5.10 6.00 6.00a 6.00ax 7.00 | 1.00 1.50
MS-DOS | WINDOWS
kbprg
The information in this article applies to:
The interrupt attribute can be applied to a function to tell the compiler that the function is an interrupt handler.
When an interrupt function is called, all registers (except SS) are saved on the stack. Examining the assembler code the compiler generates for an interrupt handler could cause confusion. When compiling without the /G1, /G2, or /G3 switch (these switches inform the compiler to generate 186, 286, or 386 code accordingly. /G3 was first available with C/C++ 7.0) the assembler code appears as it should; however, when using one of the three aforementioned switches, the assembler output may be deceiving in that the registers appear as though they are not being saved on the stack as advertised.
This potential misinterpretation results from the use of the PUSHA and PUSHAD instructions. These instructions do not exist in the 8086 instruction set, but do exist in the 80186 and later sets. The PUSHA and PUSHAD instructions push the general purpose registers onto the stack in the following order: AX, CX, DX, BX, SP, BP, SI, DI. The PUSAD instruction is available only on 80386 and later processors. For further information regarding the PUSHA and PUSHAD instructions, you should consult a reference manual for Intel's 80x86-based assembly.
The text that follows displays three partial assembler listings of an interrupt handler called func. The second case demonstrates the usage of the 186-, 286-, 386-, and 486-specific instruction PUSHA (for loadall). The third case demonstrates the usage of the 386- and 486- specific instruction PUSHAD.
/* Without G1, G2, or G3 */
_func PROC FAR
push ax
push cx
push dx
push bx
push sp
push bp
push si
push di
push ds
push es
/* With G1 or G2 */
_func PROC FAR
pusha ; This pushes all general purpose registers
push ds ; for the 80186 processors and above.
push es
/* With G3 */
_func PROC FAR
pushad ; This pushes all general purpose registers
push ds ; for the 80386 and later processors.
push es
Additional reference words: kbinf 1.00 1.50 5.10 6.00 6.00a 6.00ax 7.00
KBCategory: kbprg
KBSubcategory: CLngIss
Keywords : kb16bitonly
Last Reviewed: July 18, 1997