News:

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

macros is_eax_zero and is_eax_nonzero

Started by Larry Hammick, December 18, 2007, 11:11:25 AM

Previous topic - Next topic

Larry Hammick

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.)