The MASM Forum Archive 2004 to 2012

Miscellaneous Forums => 16 bit DOS Programming => Topic started by: Magnum on September 28, 2009, 07:39:49 PM

Title: Using AND to toggle a bit
Post by: Magnum on September 28, 2009, 07:39:49 PM
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.
Title: Re: Using AND to toggle a bit
Post by: dedndave on September 28, 2009, 07:53:27 PM
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
Title: Re: Using AND to toggle a bit
Post by: jj2007 on September 28, 2009, 08:19:40 PM
btc also does the job, but it's one byte longer.
Title: Re: Using AND to toggle a bit
Post by: FORTRANS on September 28, 2009, 10:11:41 PM
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