I'm having trouble with bit testing..

test1 dd 0000000000000001
test2 dd 0000000000000010

To build it:
xor eax,eax
or eax,test1 ;logical-or test1 to eax register

When testing for test2, with value still in eax from 'or' above..still gets processed.
push ecx ;save and clear ecx reg
xor ecx,ecx
mov ecx,eax ;mov value of eax into ecx, which is test1 above
and ecx,test2 ;logical-and the bitmask test2 to ecx register
cmp ecx,0 ;see if ecx is still 0, I would think it would be.
je continueon
....stuff here gets done regardless


Is the above correct or am I missing something? Thanks.
Posted on 2003-10-23 01:28:39 by drarem
You are comparing 1 vs 10 decimal, not binary or hex. Add the "h", or "y" as appropriate.

The code you've got below should work, but I'm wondering if instead of the "and" you've got "test", this would explain the effect you're seeing.
Remove the "cmp ecx, 0" line as it is not necessary, the "and" above it will affect the flags.

In fact if you don't care about the result, just whether or not the bit is set, the following code should work:

mov eax, test1
test eax, test2 ; And but don't save the result
jz continueon

Posted on 2003-10-23 03:32:51 by Mirno
thanks, I tried it and still the same thing. I did however put in a mov eax,1 directly before the test, so I know that part is at least working. For the constants, I tried:

test1 dd 1h
test1 dd 0000001y
test1 dd 1

neither one was successful - question, do macros affect the eax reg? If so that is what is killing me.

thanks for your help.
Posted on 2003-10-23 05:05:58 by drarem
It is entirely probable that a macro will use eax. Macros are short hand for often used bits of code, so if the particular bit of code the macro represents used eax, then eax will be corrupted by eax. Check the macro though to be sure.

Also check a list file, using the "/FlMyList.txt /Sa /Sn" switches when assembling, this will expand the macros and give you the actual code generated.

Posted on 2003-10-23 16:47:18 by Mirno
You test by byte. If you want to test a bit in a 32 bit register like eax then you consider it as 4 bytes. So if you want to test bit 15 decimal you will test like this:

test eax,08000h
jnz somewhere

In Masm always put "h" behind value or it will assume decimal value. Also in MASM if most significant bit is set than nust be proceeded by zero even in 32 bit. If you want to test bit 31 (decimal) you must test like this:

test eax,080000000h
Posted on 2003-10-23 20:57:52 by mrgone