KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

Q48444: The Interrupt Attribute Pushes Registers on the Stack

Article: Q48444
Product(s): See article
Version(s): 5.10
Operating System(s): MS-DOS
Keyword(s): ENDUSER | S_QuickC S_QuickASM | mspl13_c
Last Modified: 16-JAN-1990

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 or /G2 switch (these switches inform the
compiler to generate 186 or 286 code accordingly) the assembler code
appears as it should, however, when using one of the two
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
instruction, which does not exist in the 8086 instruction set, but
does apply to the 80186 and more recent sets. The PUSHA instruction
pushes the general purpose registers onto the stack in the following
order: AX, CX, DX, BX, SP, BP, SI, DI.  For further information
regarding the PUSHA instruction, you should consult an reference
manual for Intel's 80x86-based assembly.

The text that follows displays two partial assembler listings of an
interrupt handler called foo. The second case demonstrates the usage
of the 186, 286, 386 specific instruction PUSHA (for load all).

/* Without G1 or G2 */

_foo    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 */

 _foo    PROC FAR
        pusha              ; This pushes all general purpose registers
        push    ds         ; for the 80186 processors and above.
        push    es

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.

Copyright Microsoft Corporation 1986-2002.