Sunday, February 28, 2016

8051 Logical Operation Instructions

Logical Operations

  • A, Acc: Accumulator
  • B: B special function register
  • C: Carry flag in PSW
  • Rn: Register R7-R0 of the currently selected Register Bank.
  • dir: 8-bit internal data location’s address. This could be an Internal Data RAM location (0-127) or a SFR [i.e., I/O port, control register, status register, etc. (128-255)]. Direct Addressing Mode.
  • @Ri : 8-bit internal data RAM location (0-255) addressed indirectly through register R1or R0. Indirect Addressing Mode.
  • #data: 8-bit constant included in instruction. Immediate Addressing Mode.
  • #data 16: 16-bit constant included in instruction. Immediate Addressing Mode.
  • addr 16: 16-bit destination address. Used by LCALL and LJMP. A branch can be anywhere within the 64K byte Program Memory address space. Long Addressing Mode.
  • addr 11: 11-bit destination address. Used by ACALL and AJMP. The branch will be within the same 2K byte page of program memory as the first byte of the following instruction. Absolute Addressing Mode.
  • rel: Signed (two’s complement) 8-bit offset byte. Used by SJMP and all conditional jumps. Range is -128 to +127 bytes relative to first byte of the following instruction. Relative Addressing Mode.
  • bit: Direct Addressed bit in Internal Data RAM or Special Function Register
  • 1B: 1 byte
    2B: 2 byte
    3B: 3 byte
    1C: 1 cycle
    2C: 2 cycles
    4C: 4 cycles
    P: oscillator Period
ANLA,RnAND Register to Accumulator
ANLA,directAND direct byte to Accumulator
ANLA,@RiAND indirect RAM to Accumulator
ANLA,#dataAND immediate data to Accumulator
ANLdirect,AAND Accumulator to direct byte
ANLdirect,#dataAND immediate data to direct byte
ORLA,RnOR Register to Accumulator
ORLA,directOR direct byte to Accumulator
ORLA,@RiOR indirect RAM to Accumulator
ORLA,#dataOR immediate data to Accumulator
ORLdirect,AOR Accumulator to direct byte
ORLdirect,#dataOR immediate data to direct byte
XRLA,RnExclusive-OR Register to Accumulator
XRLA,directExclusive-OR direct byte to Accumulator
XRLA,@RiExclusive-OR indirect RAM to Accumulator
XRLA,#dataExclusive-OR immediate data to Accumulator
XRLdirect,AExclusive-OR Accumulator to direct byte
XRLdirect,#dataExclusive-OR immediate data to direct byte
CLRAClear Accumulator
CPLAComplement Accumulator
RLARotate Accumulator Left
RLCARotate Accumulator Left through the Carry
RRARotate Accumulator Right
RRCARotate Accumulator Right through the Carry
SWAPASwap nibbles within the Accumulator

Boolean operations
ANL Logical AND
ORL Logical OR
CPL Complement (logical NOT)
XRL Logical XOR (exclusive OR)

ANL A, #55h ; AND each bit in A with corresponding bit in number 55h, leaving the result in A.
ANL 42h, R4 ; AND each bit in RAM location 42h with corresponding bit in R4, leaving the result in RAM location 42h.
ORL A,@R1 ; OR each bit in A with corresponding bit in the number whose address is contained in R1 leaving the result in A.
XRL R4, 80h ; XOR each bit in R4 with corresponding bit in RAM location 80h (port 0), leaving result in A.
CPL R0 ; Complement each bit in R0

The ability to rotate the A register (accumulator) data is useful to allow examination of individual bits. The options for such rotation are as follows:
RL A ; Rotate A one bit to the left. Bit 7 rotates to the bit 0 position
RLC A ; The Carry flag is used as a ninth bit in the rotation loop
RR A ; Rotates A to the right (clockwise)
RRC A ; Rotates to the right and includes the carry bit as the 9th bit.

The Swap instruction swaps the accumulator’s high order nibble with the low-order nibble using the instruction.

Related topics:
8051 Instruction Set Overview   |   8051 Instruction Cycle   |   8051 Machine Cycle   |   8051 Instruction Set Summary   |   8051 Arithmetic Operation Instructions   |   8051 Data Transfer Instructions   |   8051 Boolean Variable Manipulation Instructions   |   8051 Program Branching Instructions   |   8051 Instruction Opcode   |   8051 Instructions that Affect Flag Settings   |   8051 Instructions and Examples

List of topics: 8051

No comments:

Post a Comment