News:

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

Using AND to toggle a bit

Started by Magnum, September 28, 2009, 07:39:49 PM

Previous topic - Next topic

Magnum

I read the intel manual for the AND command, but am having trouble understanding it's use.

I want to toggle a bit in order to change the video settings of Int 10.

For ex. toggle just the first bit  in 000010001b

Thanks.
Have a great day,
                         Andy

dedndave

AND can only be used to clear bits
you want to use XOR - a very commonly used instruction in graphics
in your example XOR the byte with 80h - toggles the high order bit
XOR the byte with 1 - toggles the low order bit

jj2007

btc also does the job, but it's one byte longer.

FORTRANS

Hi,

   AND is used to clear a bit.  Or is used to set a bit.  And
XOR "toggles" a bit.


        MOV     AL,00010001b    ; Bit pattern in AL
        AND     AL,11111110b    ; Clear low bit
                        ; AL is now 00010000b

        MOV     AL,00010001b    ; Bit pattern in AL
        OR      AL,10000000b    ; Set high bit.
                        ; AL is now 10010001b

        MOV     AL,00010001b    ; Bit pattern in AL
        XOR     AL,10000001b    ; Set high bit and low bit.
                        ; AL is now 10010000b


Regards,

Steve