Hello,
Its usually recommended not changing the stack like the series does. A better workaround is either using an assembly language file for the IRQ handler and linking it in, or using
__declspec (naked) (MSVC++ specific) which allows the function to be treated inline and you do not need to touch the stack
Code: Select all
__declspec (naked) void int_handler_5 () {
// do whatever...
_asm iretd
}
The reason for the crash is do to the _asm add esp, 12 changing the position of esp to a different value then what your current compiler configuration is set to output. add esp, 12 reverses the data pushed on the stack by the eprologue code that MSVC++ adds to the function. If it pushes a different amount of values then 12 bytes, then the instruction will, basically, make your stack (return eip) invalid causing a crash.
Using
_declspec (naked) or assembly language eliminates the need to touch the stack.