The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: Larry Hammick on December 18, 2007, 11:11:25 AM

Title: macros is_eax_zero and is_eax_nonzero
Post by: Larry Hammick on December 18, 2007, 11:11:25 AM
Of course in asm you can just go "test eax,eax" and then act on the state of the zero flag. But a subroutine might want to return a boolean value in eax, rather than (as God intended) in a flag. For that purpose:

is_eax_zero equ <db 0F7h,0D8h,01Bh,0C0h,040h>
or the equivalent
is_eax_zero macro
    neg eax
    sbb eax,eax
    inc eax
endm

is_eax_nonzero equ <db 0F7h,0D8h,01Bh,0C0h,0F7h,0D8h>
or
is_eax_nonzero macro
    neg eax
    sbb eax,eax
    neg eax
endm

These macros also put usable information in the flags. Both return ZF or NZ according to the new value of eax. Both return CF set if and only if eax was nonzero. (INC does not affect the carry flag.)