1st sorry if it's somewhere in a thread, i searched but couldn't find why i need.

Let's say i have a value (1 Byte in AL ) how can i check for the MSB n save it to another register (while AL remains unchanged) ?
PS: If it's possible to tell me. How can i make this check (for the MSB) in a 32-bit register like eax?

It may sound dull, but i'm new 2 assembly So plz explain it nicely :stupid: =)
Thanks in advance

Posted on 2003-07-16 06:35:38 by CuTedEvil
i dunno exactly but maybe this could work:

test eax,0x80000000 ;the highest bit
setz bl

the test instruction sets the zero-flag if the highest bit is zero, otherwise its cleared. then this flag is transfered to bl. you can also react on the result without putting the result in bl with jump instructions like jz or jnz.
this one will also work with test al, 0x80 and test ax, 0x8000
Posted on 2003-07-16 07:11:24 by hartyl
Look at the BSF instruction.

Posted on 2003-07-16 08:22:45 by Raymond
Another solution is the BT instruction. Awesome thing about this instruction is that it puts the bit in the Carry flag. :)
bt eax, 31 ; get bit in carry flag

rcl ebx, 1 ; put bit in another register
Posted on 2003-07-16 08:35:21 by bitRAKE
Exactly wut i wanted ;) thank you guyz :grin:

Posted on 2003-07-16 10:06:00 by CuTedEvil
Copper Ted Evil:

If you want to find the most significant set bit, then BSR is the choice as Raymond suggested.

If you just want to get the state of the bit, then there are the following ways:

cmp reg, max bit
; carry is NOT(MSB)

or reg, reg
; sign bit is the MSB

; eax = test value
; edx now has every bit set to the MSB, so and it or whatever

bt as bitRake suggested.

Also look at shl & rol, but they modify the MSB.

Posted on 2003-07-16 11:55:13 by Mirno
Thanks Mirno ;)

Posted on 2003-07-16 17:57:51 by CuTedEvil