Logical Operators

z80 » Intermediate

You can easily manipulate the different bits in a register by using commands called logical operators. There are three main logical operators: and, or,xor. Each of these commands resets all the bits in a to 0's before it starts; however, or will add in what a was before execution.

and

and arg1 - Arg1 must be either a register, a register pointing to a memory address, or a value. This sets the bits of a only if those bits are also set in arg1.
and h
and a
and %10001010

or

or arg1 - Arg1 must be either a register, a register pointing to a memory address, or a value. This sets the bits of a if those bits are set in either arg1 or a.
or b
or a
or %10010011

xor

xor arg1 - Arg1 must be either a register, a register pointing to a memory address, or a value. This sets the bits of a if they are only set in either arg1 or a but not both.
xor a
xor %10001101
xor h

Effects

and
   a = %11001001
arg1 = %10101010
   a = %10001000
		
   a = %01001101
arg1 = %01010100
   a = %01000100
		
   a = %01001101
arg1 = %01010100
   a = %01000100
or
   a = %11001001
arg1 = %10101010
   a = %11101011
		
   a = %01001101
arg1 = %01010100
   a = %01011101
		
   a = %11001010
arg1 = %11001011
   a = %11001011
	
xor
   a = %11001001
arg1 = %10101010
   a = %01100011
		
   a = %01001101
arg1 = %01010100
   a = %00011001
		
   a = %10010010
arg1 = %11010001
   a = %01000011


More from z80 » Intermediate
All the Flags // Debugging // Down-Left Bug // _GetKey Codes // Logical Operators // Memory, ROM, RAM, and Safe Areas // Miscellaneous Instructions // PC and SP // Random Numbers // TI's ROM Calls // Restart Commands // Simulated 16-bit Addition // The Stack // Tables and Arrays // Text Display // Variables