Wednesday, March 23, 2016

8051 Logical AND for Byte and Bit

Logical-AND for byte variables

ANL performs the bitwise logical-AND operation between the variables indicated and stores the results in the destination variable. No flags are affected.

The two operands allow six addressing mode combinations. When the destination is the Accumulator, the source can use register, direct, register-indirect, or immediate addressing; when the destination is a direct address, the source can be the Accumulator or immediate data.

Note: When this instruction is used to modify an output port, the value used as the original port data will be read from the output data latch, not the input pins.

ANL A,Rn
Encoding: 0 1 0 1 1 n n n

ANL A,direct address
Encoding: 0 1 0 1 0 1 0 1 direct address

ANL A,@Ri
Encoding: 0 1 0 1 0 1 1 i

ANL A,#immediate data
Encoding: 0 1 0 1 0 1 0 0 immediate data

ANL direct address,A
Encoding: 0 1 0 1 0 0 1 0 direct address

ANL direct address, #immediate data
Encoding: 0 1 0 1 0 0 1 1 direct address immediate data

ORG 0H
START :
MOV A, #0C3H
MOV R0, #01010101B
ANL A, R0 ; leaves 41H (01000001B) in A
ANL P1,#01110011B ; clears bits 7, 3, and 2 of output port 1
END; end of asm source file


ORG 0H
START :
MOV A, #35H
MOV R4, #03H
MOV 40h, #02H
MOV R0, #40H
ANL A, R4
ANL A, 40h
ANL A, @R0
ANL A, #0FH
ANL 40h, A
ANL 40h, #77h
END; end of asm source file


Logical-AND for bit variables
If the Boolean value of the source bit is a logical 0, then ANL C clears the carry flag; otherwise, this instruction leaves the carry flag in its current state. A slash ( / ) preceding the operand in the assembly language indicates that the logical complement of the addressed bit is used as the source value, but the source bit itself is not affected. No other flags are affected.

Only direct addressing is allowed for the source operand.

ANL C,bit
Encoding: 1 0 0 0 0 0 1 0 bit address

ANL C,/bit
Encoding: 1 0 1 1 0 0 0 0 bit address

; Set the carry flag if, and only if, P1.0 = 1, ACC.7 = 1, and OV = 0:

ORG 0H
START :
MOV C, P1.0 ; LOAD CARRY WITH INPUT PIN STATE
ANL C, ACC.7 ; AND CARRY WITH ACCUM. BIT 7
ANL C, /OV ; AND WITH INVERSE OF OVERFLOW FLAG
END; end of asm source file


ORG 0H
START :
CLR C
SETB 22h
ANL C, 22h ; C = C & 1
ANL C, /22h ; C = C & 0
END; end of asm source file



Related topics:
8051 Increment Byte and DPTR   |   8051 Decrement Byte   |   8051 Logical OR for Byte and Bit   |   8051 Logical XOR for Byte   |   8051 Addition

List of topics: 8051

No comments:

Post a Comment