0

As the title suggests I want to set SF=1 (if it was 1 before then I should keep it that way) with the commands pushfq and popfq.

To begin with, I don't understand how would pushing and popping rflags to and from the stack could change flags values.

architecture is Intel x86-64

Peter Cordes
  • 245,674
  • 35
  • 423
  • 606
Eliran Turgeman
  • 758
  • 2
  • 3
  • 19
  • 1
    Obviously you modify the copy in stack memory at `[rsp]` between push and pop. – Peter Cordes Dec 12 '20 at 12:50
  • Does that happen since pop and push actually perform some arithmetic operation with `rsp` that will change SF if the operation sign is negative? – Eliran Turgeman Dec 12 '20 at 13:34
  • 3
    No, *you* have to write an instruction between the push and the pop. If you just push/pop back to back, you'll restore RFLAGS unchanged. But you do need the push/pop, otherwise you can only change RFLAGS by running an instruction like `cmp` or `shl`. Some flags (like CF) have instructions to set/clear/toggle just that one (e.g. `stc`) but there's no such instruction for SF, so if you want to change it without affecting other FLAGS, you have to store/modify/reload FLAGS to somewhere you can use normal instructions on it. – Peter Cordes Dec 12 '20 at 13:35

0 Answers0