Search code examples
assemblygccx86calling-conventionstatus-register

Saving Status register (EFLAGS) when calling a function


As I understand, when I'm calling a function, based on GCC Calling Convention, this is what happens:

Caller saves values of AX, CX and DX registers. Arguments and returning address are pushed on stack. Also, callee must preserve values of SI, DI, BX and BP registers.

But, what about Status register? Who saves it?

Also, is value of returning address which is pushed on stack actually value of Instruction register?


Solution

  • The status register is not preserved across function calls. If there's something important in the status register it needs to be copied elsewhere (generally with SETcc), but the calling convention doesn't require the calling function to do this, just as it doesn't require the calling function to save and restore AX et al. if there's nothing important in them.