The MASM Forum Archive 2004 to 2012

Miscellaneous Forums => 16 bit DOS Programming => Topic started by: yodacool on June 06, 2005, 03:00:06 PM

Title: Testing a register for zero
Post by: yodacool on June 06, 2005, 03:00:06 PM
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
....
Title: Re: Testing a register for zero
Post by: MichaelW on June 06, 2005, 03:33:02 PM
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