Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assembly: do MOV or DEC influence zero flag?

In a disassembled code:

movsx eax,[address1]
# a few fpu computations
dec eax
# so many fpu computations
jz label2

If fpu computations do not influence zero flag, then we can assume that it is equal to:

# a few fpu computations
# so many fpu computations
movsx eax,[address1]
dec eax
jz label2

Then, my question is that do mov or dec have any influence on zero flag?

like image 789
barej Avatar asked Aug 16 '15 04:08

barej


2 Answers

Of course you should look this up in the manuals but here's a general rule:

  • Instructions that move stuff around don't modify the flags.
  • Instructions that do computations will modify the flags.

So movsx falls in the first category and will not change any flag.
But dec clearly does a computation and most certainly changes several flags including the ZeroFlag.

like image 140
Sep Roland Avatar answered Oct 19 '22 23:10

Sep Roland


  • Check your assumptions.

    If fpu computations do not influence zero flag, then we can assume that it is equal to:

    1. There exist 4 fpu instructions that modify the EFLAGS register directly. These are fcomi, fcomip, fucomi, and fucomip. They define the ZF, PF, and CF.
      You would have to peruse the # so many fpu computations(2) code block for any of these. If present jz label2 will not be based on the outcome of dec eax!

    2. There exist 2 fpu instructions that modify the AX register. These are fstsw ax and fnstsw ax.
      You would have to peruse both the # a few fpu computations(1) and # so many fpu computations(2) code blocks for any of these. If present EAX will not contain the value that you expect!

  • To answer your question about mov and dec having any influence on the ZF the general rule provided by @user3144770 pretty much says it all.

    The Intel manual is a reliable friend in these matters.

like image 42
Fifoernik Avatar answered Oct 20 '22 00:10

Fifoernik