0

Sometimes I need store values in stack and than compare it. So, I do something like this:

Check:
  push eax          ; save
  mov eax, edx      ; calc edx+esi+8
  add eax, esi
  add eax, 8
  cmp eax, [SomeVar]
  jne Code          ; if not goto Code
  pop eax           ; restore stack
  jmp Exit          ; quit

Code:
  pop eax           ; restore stack if no

Exit:
...

So, is it correct way to do popping that way (only once):

Check:
  push eax          ; save
  mov eax, edx      ; calc edx+esi+8
  add eax, esi
  add eax, 8
  cmp eax, [SomeVar]
  pop eax           ; <-- pop after cmp
  jne Code          ; <-- jump after pop
  jmp Exit          ; quit

Code:
  ; pop eax         ; no pop needs here

Exit:
...
2
  • 2
    Either way works (since pop does not modify flags), but obviously the second way is more compact. I also note that you could reduce jne Code; jmp Exit to je Exit, but I guess this is just sample code. Sep 9, 2019 at 9:23
  • 2
    "calc edx+esi+8" you may want to have a look at what leadoes
    – Tommylee2k
    Sep 9, 2019 at 10:09

1 Answer 1

4

Yes. Pop does not change the flags, so putting the pop after the comparison before the conditional branch is fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.