Arithmetic Logical Instructions
for
8051 Microcontroller
-A.Usha Rani,
-Lecturer, Department of Physics and Electronics,
-St.Ann’s College for Women
ARITHMETIC INSTRUCTIONS
These instructions perform arithmetic operations.
The arithmetic operations modify Carry, Overflow
and Auxiliary carry flags based on the result of the
operation
The status of the flags can be used a test conditions.
ADDITION
The mnemonic for addition is ADD.
ADD A, source //Add contents of A with operand
source and store result in A
All addressing modes can be used for this instruction.
The register A is always the destination as well as one of
the source operands.
ADD A, # data //Add contents of A with immediate data
and store result in A
ADD A, #10H // Add the value 10H to the contents of A
and store the result in A
ADD A,Rn //Add contents of A with contents of Rn
and store result in A
ADD A, R3 //Add contents of A with contents of
register R3 and store result in A
ADD A, direct //Add contents of A with contents of
address direct and store result in A
ADD A, 45H //Add contents of A with contents of
address 45 H and store result in A
ADD A, @Ri // Add contents of A with contents of
address in Ri
ADD A, @R0 // Add contents of A with contents of
address in R0
SUBTRACTION
The mnemonic is SUBB
SUBB A, Source //Subtract the operand source
from contents of A and store result in A
SUBB A, # data // Subtract immediate data and carry
from A and store result in A
SUBB A, #10H // Subtract immediate data 10H and
carry from A and store result in A
SUBB A,Rn //Subtract contents of Rn and carry
from A and store result in A
SUBB A, R3 //Subtract contents of R3 and
carry from A and store result in A
SUBB A, direct // Subtract contents of address direct
and carry from A and store result in A
SUBB A, 45H // Subtract contents of address 45H and
carry from A and store result in A
SUBB A, @Ri //Subtract contents and carry of address
in Ri from A and store result in A
SUBB A, R0 //Subtract contents and carry of address
in R0 from A and store result in A
MULTIPLICATION
Multiplication uses only the registers A and B as source
and destination.
MULAB //Multiply the contents of A with B
and put lower byte of result in A
and higher byte of result in B.
DIVISION
Division uses only the registers A and B as source and
destination.
 The number in A is divided by the number in B.
Quotient is placed in A and remainder is placed in B.
DIV AB // Divide the contents of A with
contents of B and result (quotient)in
A and remainder in B.
INCREMENT
Used to add 1 to a operand.
Supports all addressing modes.
No flags are effected.
Useful to repeat the operations i.e to increment
till the desired result is obtained.
INC destination // Add 1 to the destination
operand.
INC A //Increment the contents of A by 1
INC A //Increment the contents of A by 1
INC Rn // Increment the contents of Rn by 1
INC R3 // Increment the contents of R3 by 1
INC @Ri // Increment the contents of address
pointed by Ri by1
INC @R0 // Increment the contents of address
pointed by R0 by1
INC Direct //Increment the contents of direct
address by 1
INC 45H //Increment the contents of direct
address 45H by 1
INC DPTR //Increment the contents of DPTR by 1
INC DPTR //Increment the contents of DPTR by 1
DECREMENT
Used to subtract 1 from a operand.
Supports all addressing modes.
No flags are effected.
Useful to repeat the operations i.e to
increment till the desired result is obtained.
DEC destination //Subtract 1 from
destination operand
DEC A // Decrement the contents of A by 1
DEC A // Decrement the contents of A by 1
DEC Rn // Decrement the contents of Rn by 1
DEC R3 // Decrement the contents of R3 by 1
DEC @Ri // Decrement the contents of address
pointed by Ri by1
DEC @R0 // Decrement the contents of address
pointed by R0 by1
DEC Direct // Decrement the contents of direct
address by 1
DEC 45H // Decrement the contents of direct
address by 1
DEC DPTR //Decrement the contents of DPTR by 1
DEC DPTR //Decrement the contents of DPTR by 1
LOGICAL INSTRUCTIONS
8051 supports the following logical operations
AND
OR
EX_OR
 NOT
AND Operation
ANLA,#data //Bitwise AND operation of A with data
ANLA,Rn // Bitwise AND operation of A with Rn
ANLA,@Ri //Bitwise AND operation of A with data
pointed by Ri
ANLA,direct // Bitwise AND operation of A with data
in direct
ANL direct, #data // Bitwise AND operation of data in
direct with immediate data
ANL direct, A // Bitwise AND operation of data in
address direct with A
OR Operation
ORLA,#data // Bitwise OR operation of A with data
ORLA,Rn // Bitwise OR operation of A with Rn
ORLA,@Ri // Bitwise OR operation of A with data
pointed by Ri
ORLA,direct // Bitwise OR operation of A with data
in direct
ORL direct, #data // Bitwise OR operation of data in
direct with immediate data
ORL direct, A // Bitwise OR operation of data in
address direct with A
Ex-OR Operation
XRLA,#data // Bitwise X-OR operation of A with data
XRLA,Rn // Bitwise X-OR operation of A with Rn
XRLA,@Ri // Bitwise X-OR operation of A with data
pointed by Ri
XRLA,direct // Bitwise X-OR operation of A with data
in direct
XRL direct, #data // Bitwise X-OR operation of data in
direct with immediate data
XRL direct, A // Bitwise X-OR operation of data in
address direct with A
UNARY OPERATIONS
XRLA,#data //Bitwise X-OR operation of A with data
XRLA,Rn // Bitwise X-OR operation of A with Rn
XRLA,@Ri //Bitwise X-OR operation of A with data
pointed by Ri
XRLA,direct // Bitwise X-OR operation of A with
data in direct
XRL direct, #data //Bitwise X-OR operation of data
in direct with immediate data
XRL direct, A // Bitwise X-OR operation of data in
address direct with A

Arithmetic and logical instructions 8051 microcontroller

  • 1.
    Arithmetic Logical Instructions for 8051Microcontroller -A.Usha Rani, -Lecturer, Department of Physics and Electronics, -St.Ann’s College for Women
  • 2.
    ARITHMETIC INSTRUCTIONS These instructionsperform arithmetic operations. The arithmetic operations modify Carry, Overflow and Auxiliary carry flags based on the result of the operation The status of the flags can be used a test conditions.
  • 3.
    ADDITION The mnemonic foraddition is ADD. ADD A, source //Add contents of A with operand source and store result in A All addressing modes can be used for this instruction. The register A is always the destination as well as one of the source operands.
  • 4.
    ADD A, #data //Add contents of A with immediate data and store result in A ADD A, #10H // Add the value 10H to the contents of A and store the result in A ADD A,Rn //Add contents of A with contents of Rn and store result in A ADD A, R3 //Add contents of A with contents of register R3 and store result in A
  • 5.
    ADD A, direct//Add contents of A with contents of address direct and store result in A ADD A, 45H //Add contents of A with contents of address 45 H and store result in A ADD A, @Ri // Add contents of A with contents of address in Ri ADD A, @R0 // Add contents of A with contents of address in R0
  • 6.
    SUBTRACTION The mnemonic isSUBB SUBB A, Source //Subtract the operand source from contents of A and store result in A
  • 7.
    SUBB A, #data // Subtract immediate data and carry from A and store result in A SUBB A, #10H // Subtract immediate data 10H and carry from A and store result in A SUBB A,Rn //Subtract contents of Rn and carry from A and store result in A SUBB A, R3 //Subtract contents of R3 and carry from A and store result in A
  • 8.
    SUBB A, direct// Subtract contents of address direct and carry from A and store result in A SUBB A, 45H // Subtract contents of address 45H and carry from A and store result in A SUBB A, @Ri //Subtract contents and carry of address in Ri from A and store result in A SUBB A, R0 //Subtract contents and carry of address in R0 from A and store result in A
  • 9.
    MULTIPLICATION Multiplication uses onlythe registers A and B as source and destination. MULAB //Multiply the contents of A with B and put lower byte of result in A and higher byte of result in B.
  • 10.
    DIVISION Division uses onlythe registers A and B as source and destination.  The number in A is divided by the number in B. Quotient is placed in A and remainder is placed in B. DIV AB // Divide the contents of A with contents of B and result (quotient)in A and remainder in B.
  • 11.
    INCREMENT Used to add1 to a operand. Supports all addressing modes. No flags are effected. Useful to repeat the operations i.e to increment till the desired result is obtained. INC destination // Add 1 to the destination operand.
  • 12.
    INC A //Incrementthe contents of A by 1 INC A //Increment the contents of A by 1 INC Rn // Increment the contents of Rn by 1 INC R3 // Increment the contents of R3 by 1 INC @Ri // Increment the contents of address pointed by Ri by1 INC @R0 // Increment the contents of address pointed by R0 by1
  • 13.
    INC Direct //Incrementthe contents of direct address by 1 INC 45H //Increment the contents of direct address 45H by 1 INC DPTR //Increment the contents of DPTR by 1 INC DPTR //Increment the contents of DPTR by 1
  • 14.
    DECREMENT Used to subtract1 from a operand. Supports all addressing modes. No flags are effected. Useful to repeat the operations i.e to increment till the desired result is obtained. DEC destination //Subtract 1 from destination operand
  • 15.
    DEC A //Decrement the contents of A by 1 DEC A // Decrement the contents of A by 1 DEC Rn // Decrement the contents of Rn by 1 DEC R3 // Decrement the contents of R3 by 1 DEC @Ri // Decrement the contents of address pointed by Ri by1 DEC @R0 // Decrement the contents of address pointed by R0 by1
  • 16.
    DEC Direct //Decrement the contents of direct address by 1 DEC 45H // Decrement the contents of direct address by 1 DEC DPTR //Decrement the contents of DPTR by 1 DEC DPTR //Decrement the contents of DPTR by 1
  • 17.
    LOGICAL INSTRUCTIONS 8051 supportsthe following logical operations AND OR EX_OR  NOT
  • 18.
    AND Operation ANLA,#data //BitwiseAND operation of A with data ANLA,Rn // Bitwise AND operation of A with Rn ANLA,@Ri //Bitwise AND operation of A with data pointed by Ri ANLA,direct // Bitwise AND operation of A with data in direct ANL direct, #data // Bitwise AND operation of data in direct with immediate data ANL direct, A // Bitwise AND operation of data in address direct with A
  • 19.
    OR Operation ORLA,#data //Bitwise OR operation of A with data ORLA,Rn // Bitwise OR operation of A with Rn ORLA,@Ri // Bitwise OR operation of A with data pointed by Ri ORLA,direct // Bitwise OR operation of A with data in direct ORL direct, #data // Bitwise OR operation of data in direct with immediate data ORL direct, A // Bitwise OR operation of data in address direct with A
  • 20.
    Ex-OR Operation XRLA,#data //Bitwise X-OR operation of A with data XRLA,Rn // Bitwise X-OR operation of A with Rn XRLA,@Ri // Bitwise X-OR operation of A with data pointed by Ri XRLA,direct // Bitwise X-OR operation of A with data in direct XRL direct, #data // Bitwise X-OR operation of data in direct with immediate data XRL direct, A // Bitwise X-OR operation of data in address direct with A
  • 21.
    UNARY OPERATIONS XRLA,#data //BitwiseX-OR operation of A with data XRLA,Rn // Bitwise X-OR operation of A with Rn XRLA,@Ri //Bitwise X-OR operation of A with data pointed by Ri XRLA,direct // Bitwise X-OR operation of A with data in direct XRL direct, #data //Bitwise X-OR operation of data in direct with immediate data XRL direct, A // Bitwise X-OR operation of data in address direct with A