AND (assembler)

From C64-Wiki
Jump to navigationJump to search
Disambiguation The title of this article is ambiguous. AND (Disambiguation).

Remark: This article describes the assembler/machine language instruction AND. For information on the BASIC operator of the same name, see AND (BASIC).

AND (short for "Logic AND") is the mnemonic for a machine language instruction which performs a bit-wise boolean "and" between the eight bits in the operand and the eight bits of the accumulator. Each resulting bit is a one (1) only if the corresponding bits of the operand and the accumulator are also one (1). If either corresponding bit is zero (0) then the resulting bit will be zero (0). The result is stored in the accumulator. In this way, the AND operation masks the value in the accumulator with the value in the operand.

Addressing modes[edit]

Opcode Addressing
in bytes
Number of
Dec Hex
41 29 Immediate AND #nn 2 2
45 2D Absolute AND nnnn 3 4
61 3D Absolute,X AND nnnn,X 3 4*
57 39 Absolute,Y AND nnnn,Y 3 4*
37 25 Zeropage AND nn 2 3
53 35 Zeropage,X AND nn,X 2 4
33 21 Indexed-indirect AND (nn,X) 2 6
49 31 Indirect-indexed AND (nn),Y 2 5

AND supports eight different addressing modes to determine the operand, as shown in the table at right. In the assembler formats listed, nn represents a single-byte (8-bit) figure, and nnnn is a two-byte (16-bit) address.
With some addressing forms (marked with an asterisk, *, in the "Number of cycles" column) the execution time for AND depends on the circumstances: In cases where the indexing requires the CPU to "reach across" a page boundary from the base address, the execution time is 1 cycle longer than listed here.

CPU flags[edit]

AND affects 2 of the CPU's status flags:

  • The negative status flag is set if the result is negative, i.e. has its most significant bit set.
  • The zero flag is set if the result is zero, or cleared if it is non-zero.