BX Register Is Popped Twice for a C Interrupt FunctionLast reviewed: July 17, 1997Article ID: Q50518 |
6.00 6.00a 6.00ax 7.00 | 6.00 6.00a | 1.00 1.50 1.51 1.52
MS-DOS | OS/2 | WINDOWSkbtool The information in this article applies to:
SUMMARYThe interrupt keyword is used to designate specific C functions as interrupt service routines and instructs the compiler to generate appropriate entry and exit instructions. If you compile code with the /G1 or /G2 option (80186 or 80286 code generation), then the compiler produces pusha and popa instructions that save and restore all vital registers. However, if you compile with the default /G0 (8086 code generation), then the registers are each explicitly pushed and popped. One difference, which may at first appear to be a problem in this code, is that the BX register is popped twice but the SP register is not popped at all. This is not a problem. The SP register is saved in the following instruction sequence:
mov bp, sp . . ISR code . mov sp, bp MORE INFORMATIONThe peculiar double popping of BX can be explained by the following:
The first pop of SP to BX is necessary to remove the previous value of SP from the stack. The second pop of BX is necessary to restore the old BX value. The old value of SP was restored in the "MOV SP,BP" instruction, which immediately precedes the popping of all the registers. This ensures that the state of the registers are saved and then restored in the Interrupt Service Routine.
Sample Code
/* Compiler Options Needed: /Fc /G0 (or /G1)
*/
#include <stdio.h>
#include <dos.h>
void __interrupt __far func1(unsigned _es, unsigned _ds,
unsigned _di, unsigned _si )
{}
void main(void)
{}
|
Additional reference words: kbinf 1.00 1.50 6.00 6.00a 6.00ax 7.00 8.00
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |