9.arithmetic Instructions PDF
9.arithmetic Instructions PDF
• Add
• Subtract
• Increment
• Decrement
• Multiply
• Divide
• Decimal adjust
Arithmetic Instructions
Mnemonic Description
ADD A, byte add A to byte, put result in A
ADDC A, byte add with carry
SUBB A, byte subtract with borrow
INC A increment A
INC byte increment byte in memory
INC DPTR increment data pointer
DEC A decrement accumulator
DEC byte decrement byte
MUL AB multiply accumulator by b register
DIV AB divide accumulator by b register
DA A decimal adjust the accumulator
ADD Instructions
add a, byte ; a a + byte
addc a, byte ; a a + byte + C
These instructions affect 3 bits in PSW:
C = 1 if result of add is greater than FF
AC = 1 if there is a carry out of bit 3
OV = 1 if there is a carry out of bit 7, but not from bit 6, or
visa versa.
Instructions that Affect PSW bits
Example:
SUBB A, #0x4F ; A A – 4F – C
mov a, r2
add a, #1 ; use add rather than increment to affect C
mov r2, a
mov a, r3
addc a, #0 ; add C to most significant byte
mov r3, a
MUL AB ; BA A * B
Integer Division
DIV AB ; divide A by B
A Quotient(A/B), B Remainder(A/B)
Example:
mov a, #0x23
mov b, #0x29
add a, b ; a 23 + 29 = 4C (wanted 52)
DA a ; a a + 6 = 52