News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Testing a register for zero

Started by yodacool, June 06, 2005, 03:00:06 PM

Previous topic - Next topic

yodacool

Newbie question:
What is a good way to test a register (say AX) for zero?
Lets say AX=4

CMP AX,0
JZ done
---
would that work?
Or would it be easier to:
push AX ;save ax for later
add ax,3
sub ax,3
JZ done
....

MichaelW

Any of these will work OK:

    cmp   ax,0
    jz    done
    or    ax,ax
    jz    done
    test  ax,ax
    jz    done
  done:

And here is the generated code:

0A4D:0010 83F800        CMP     AX,+00
0A4D:0013 7408          JZ      001D
0A4D:0015 0BC0          OR      AX,AX
0A4D:0017 7404          JZ      001D
0A4D:0019 85C0          TEST    AX,AX
0A4D:001B 7400          JZ      001D

eschew obfuscation