Detect null byte in a (16 bit) word in Assembly

185 Views Asked by At

I have to detect a null byte in a word, So I have to check if 8 of the 16 bits are zero, so basically either the front 8 bits or the back. The problem is I can't use a lot of cycles. So I need a bit mask, that checks the front and the back in just one operation. So first checking bl and then bh doesn't work as it takes to long. The other null byte posts never really address a real 16-bit word. (assembly)

I already tried 0xff and 0x00ff but can't combine them into one bit mask

1

There are 1 best solutions below

4
rcgldr On

A mask isn't needed, but it takes two instructions:

        mul     ah      ;multiply al by ah
        test    ax,ax   ;set zero flag if ax = 0