News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

help with BT/BTS

Started by mstrcool, April 28, 2008, 04:54:31 AM

Previous topic - Next topic

mstrcool

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!

hutch--

mstrcool,

Just show us what you are trying to test and I am sure someone can help you.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

donkey

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
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable