Assembly: do MOV or DEC influence zero flag?
Asked Answered
S

2

6

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?

Staid answered 16/8, 2015 at 4:1 Comment(4)
Did you look up MOV and DEC in Intel's manual? What did it say?Coma
@Michael, multiple huge books. I don't know which one to read. Does assembly have any wiki page?Staid
@Staid volume 2, chapter 3 (a-m)Keilakeily
I updated the x86 tag wiki recently. It mentions the instruction set ref manual in the description of that Intel link. Intel's manual has pseudocode and text (and diagrams where needed) for every instruction showing exactly happens to the machine state.Julissajulita
O
14

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.

Overrun answered 16/8, 2015 at 14:27 Comment(1)
There are 2 notable exceptions in the basic ALU instructions that x86 has had since 8086: not doesn't touch flags. (Unlike neg which is equivalent to sub from 0.) lea doesn't touch flags either. Also notable is that not all instructions update every flag. inc/dec leave CF unmodified.Julissajulita
F
6
  • 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.

Faceless answered 21/8, 2015 at 15:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.