Log in

View Full Version : Saving Registers & Flags


Maze
April 21st, 2009, 17:19
When replacing assembly code, whats the best way to save all the registers and flags ?
I'm currently using the following instructions...

pushfd
pushad
~My Code~
popad
popfd

Does that work with most processors ?
Any other suggestions ?

Thanks !

squidge
April 22nd, 2009, 07:19
All processors that use the X86 instruction set, yes, that will work.

Otherwise you'll have to read the instruction set for the processor you are using, obviously. So for processors that use the ARMvX instruction set, you'll find that STMFD is more suitable.

int0
May 5th, 2009, 04:41
Yes pushfd pushad will work, unlike LAHF/SAHF load/save flags into/from AH register too bad but new AMD CPUs don't support this instruction which is much faster than pushfd.