1

How would one, for example, set the CF, clear SF, clear DF, toggle ZF and toggle OF, after using the pushf instruction?
Without altering the remaining flags.
I assume logic operands would be used in some cases.
Thanks

Monica
  • 33
  • 4
  • Yes, modify `dword [esp]` or `qword [rsp]` with AND, OR, or XOR, then use `popf`. The position of each bit is documented, and even has its own wikipedia article: https://en.wikipedia.org/wiki/FLAGS_register – Peter Cordes Nov 26 '17 at 07:13
  • To specifically do all the things you want, you'll need at least 2 boolean instructions (AND and XOR), so you might want to pop flags back into `eax` or something instead of using 2 memory-destination instructions. – Peter Cordes Nov 26 '17 at 07:22
  • **Use an AND to clear all the bits you want to set or clear, then an XOR to set or toggle all the bits you want set/toggled**. (This saves using an OR to unconditionally set any bits: unconditionally clearing and then toggling with XOR does the same thing, and if you need to toggle any then you need the XOR.) – Peter Cordes Nov 26 '17 at 07:24
  • @Monica At `[esp]` you'll find bits #0...#7, at `[esp+1]` you'll find bits #8...#15. If this is 32-bit code then it goes on until at `[esp+3]` you'll find bits #24...#31. – Sep Roland Nov 26 '17 at 17:05

0 Answers0