The Interrupt Attribute Pushes Registers on the Stack

Last reviewed: July 17, 1997
Article 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:

  • Microsoft C for MS-DOS, versions 5.1, 6.0, 6.0a, and 6.0ax
  • Microsoft C/C++ for MS-DOS, version 7.0
  • Microsoft Visual C++ for Windows, versions 1.0 and 1.5

SUMMARY

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.

MORE INFORMATION

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


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 17, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.