The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: mstrcool on April 28, 2008, 04:54:31 AM

Title: help with BT/BTS
Post by: mstrcool on April 28, 2008, 04:54:31 AM
hey guys!
After somedays trying to use BT and BTS instructions, the result was bad.
I really cant understand how this works  :(

can ayone help me with something like: "BT and BTS for dummies  :U"?

greetings!
Title: Re: help with BT/BTS
Post by: hutch-- on April 28, 2008, 08:24:56 AM
mstrcool,

Just show us what you are trying to test and I am sure someone can help you.
Title: Re: help with BT/BTS
Post by: donkey on April 28, 2008, 04:03:22 PM
BT (Bit Test) sets the carry flag based on the state (0/1) of the bit being tested...

mov EAX, 4 // set the third bit
BT EAX,2 // Remember to count bits starting at 0 so the third bit is index 2
JNC >>
// Bit 2 is 1 so the carry flag is set to 1
PrintText("The bit is set")
:


BTS (Bit Test and Set) sets the carry flag in the same way as BT but on exit it will set the bit you are checking to 1

mov EAX, 0 // reset all bits
BTS EAX, 2 // check any bit
JC >>
// Bit 2 is 0 so the carry flag is set to 0
PrintText("The bit is not set")
:
// Bit 2 has been set so a check will show it is now 1
BT EAX, 2 // check any bit
JNC >>
PrintText("The bit is set")
:


Interesting things to do with it. Saturate EAX with a single bit...

mov EAX, 4
BT EAX,2
SALC
MOVSX EAX,AL