user1158332
user1158332

Reputation: 53

ASM x86 is it correct pop immediately after cmp?

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:
...

Upvotes: 0

Views: 601

Answers (1)

prl
prl

Reputation: 12435

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

Upvotes: 4

Related Questions