I have a simple assembly function called from a c program and I have to use a instruction (FIDIV) that needs a memory operand.
Is it safe to move the value to [esp - 2] and use it in the next instruction or is it never safe to use the stack that way?
I know there are many workarounds, and I really don’t need this anymore, so now it’s just curiosity.
Using an offset like that will definately expose the data to corruption any time any action on the thread needs to touch the stack again. This can occur during interrupts, APCs, context switches, exceptions, etc. What you’ll want to do instead is to actually reserve space on the stack and save a pointer to it.
Of course if you only need a few bytes, the push instruction is much faster