AND - The Bitwise AND Command

The AND command is a bitwise operation that AND’s the value held in the accumulator with the specified value (argument) and resaves the new value into the accumulator.
"AND"ing a bit turns it off. The value you specify in the command is known as a mask. Bits in the argument that are off will become off in the result. Bits that are on in the argument will maintain state in the result.
This makes the command useful for either turning a single bit off or turning off all but one bit.
Sometimes it is useful to store binary states in a single byte and use bitwise operations like this to do targeted edits. One example would be tracking partition states in a ballroom.
This command is the opposite of the OR command.

Example Bitfield for AND command

ACC

1

1

1

0

0

0

0

1

MASK

0

1

1

0

1

1

0

0

RESULT

0

1

1

0

0

0

0

0

Syntax

AND x
Where x is the value, memory location, or tasking port you want to AND against the accumulator value.

Examples

Example 1

{
LDA #0xA6   //Load the accumulator with a value of 0xA6
AND #0x0F   //AND it with 0x0F turning off bits 5-8
STA ~1      //Store the new value of 0x06 into ~1
}

Example 2

Using AND to mask out all but one dipswitch.

{
LDA ^17,0           //Load the first 8 dry contacts
AND #0x04           //AND it with 0x04 and mask out all but input 3
BRZ Switch3Released //If released branch, if not assume pressed
...
}

Example 3

This excerpt stores the state of a partition into a single byte tracking all of them.

{
...
Partition1:
		LDA PresetByte			//get preset byte
		CMP #0					//preset 1
		BRZ Part1P1
		CMP #3					//preset 4
		BRZ Part1P4
		Null
		Part1P1:					//Partition open
			LDA RoomState
			OR #0x01				//Set the bit to on
			STA RoomState
			BRA SendMessage
		Part1P4:					//Partition closed
			LDA RoomState
			AND #0xFE				//Set the bit to off
			STA RoomState
			BRA SendMessage
...
}