Perfectly understandable mistake ;)
Especially when you've been staring at a monitor all day.
Posted on 2002-03-15 23:41:24 by iblis
To Steve:
I don't get what you meant.
To All:
Just one more example, I wrote the following code
as part of flag analyzing routin. The perpose of code is
to put in ebx index of right case of three possible cases
case eax = 0,
case eax has signle bit set (in context of
the topic single bit = eax contents power of 2)
case eax has more than 1 bit set.

Index in ebx then maybe used for unbranchable call(jmp)
to appropriate code handling the case, or (and) for loading
data using it as index.



xor ebx,ebx ;1
mov edx,eax ;0
cmp ebx,eax ;1
lea ecx,[eax][-1] ;0
adc ebx,0 ;1
xor edx,ecx ;0
and edx,eax ;1
cmp edx,eax ;1
adc ebx,0 ;1
Posted on 2002-03-16 00:10:30 by The Svin

As for BitRAKEs method, why not:
PowerOfTwo MACRO regmem:REQ

;; return EAX zero if regmem is a power of two
mov eax, regmem
; mov edx, regmem ;Not needed
dec eax
sbb edx,edx
and eax, regmem
xor eax, edx
ENDM


Or even:


mov edx, eax
dec eax
and eax, edx
; eax zero of powers of 2, non-zero for not
I see that you forget DEC instruction doesn't effect the carry flag. And in the second case - stryker already posted that method - which returns an incorrect result for zero. I was just supplying a fix for that case. Thanks for catching the extra instruction. :)
Posted on 2002-03-16 01:18:28 by bitRAKE