ARITHMETIC INSTRUCTIONS
Here you will see operations like:
~ Addition
~ Addition with Carry
~ Subtraction with Borrow
~ Increment
~ Decrement
~ Multiply
~ Divide
~ Decimal Adjustment after addition
1) ADD A, #n
Example: ADD A, #25H;
Operation: Adds A Register with Immediate data. Stores the result in A Register.
No of cycles required: 1
Note: Please do remember to check for carry after performing addition.
2) ADD A, Rr
Example: ADD A, R0;
Operation: Adds A Register with the value of a RAM register. Stores the result in A
Register.
No of cycles required: 1
3) ADD A, addr
Example: ADD A, 25H;
Operation: Adds A Register with the contents of the address. Stores the result in A Register.
No of cycles required: 1
4) ADD A, @Rp
Example: ADD A, @R0;
Adds A Register with the contents of the location pointed by the register.
Result is stored in A Register
If R0 = 20H and Location 20H contains value 35H, then 35H will be added to A register.
5) ADDC A, #n
Example: ADDC A, #25H;
Adds A Register with Immediate data along with the Carry of the previous
addition which is present in the Carry Flag. Stores the result in A Register.
ADDC is used when we want to ADD two large numbers like 16 bit numbers.
First we add the lower bytes using ADD instruction. Then we add the higher bytes
using ADDC instruction. If the Lower byte has produced a Carry, then CF will be
1.This Carry will be added into the higher bytes.
Example of adding 12FFH + 0001H = 1300H
6) ADDC A, Rr
Example: ADDC A, R0;
Adds A Register with the value of a RAM register along with the Carry of the
previous addition. Stores the result in A Register.
7) ADDC A, addr
Example: ADDC A, 25H
Adds A Register with the contents of the address along with the Carry of the
previous addition. Stores the result in A Register.
8) ADDC A, @Rp
Example: ADDC A, @R0;
Adds A Register with the contents of the location pointed by the register along
with the Carry of the previous addition. Result is stored in A Register
9) SUBB A, #n
Example: SUBB A, #25H;
Performs A Register – Immediate data – Carry Flag (Carry Flag holds the
borrow of the previous subtraction). Stores the result in A Register
SUBB is used when we want to subtract two large numbers like 16 bit numbers.
First we subtract the lower bytes. If the Lower byte subtraction needs a borrow, then CF will be 1.This Carry will be subtracted from the higher bytes. It is important to realize that there is no ordinary SUB instruction. Hence if we want to perform simple 8-bit subtraction, we still have to use SUBB instruction.
10) SUBB A, Rr
Example: SUBB A, R0;
Performs A Register – value of RAM register – Carry Flag (Carry Flag holds the
borrow of the previous subtraction). Stores the result in A Register.
11) SUBB A, addr
Example: SUBB A, 25H;
Performs A Register – contents of memory address – Carry Flag (Carry Flag
holds the borrow of the previous subtraction).Stores the result in A Register
12) SUBB A, @Rp
Example: SUBB A, @R0;
Performs A Register – Contents of the memory location pointed by the register –
Carry Flag. Result is stored in A Register.
13)INC A
Example: INC A;
Increments the value of A register. Stores the result in A Register
14)INC Rr
Example: INC R0;
Increments the value of a RAM register. Stores the result in the same RAM
Register
15) INC addr
Example: INC 25H;
Increments the contents of a memory address. Stores the result back in the
same location.
16)INC @Rp
Example: INC @R0;
Increments the contents of a memory location pointed by R0. Will store the
result back at the same location
17)INC DPTR
Example: INC DPTR;
Increments the 16-bit value of DPTR register. Stores the result in DPTR Register
No of cycles required: 2
18) DEC A
Example: DEC A;
Decrements the value of A register. Stores the result in A Register.
During DEC A, if A was 00H, it will roll back to FFH. That’s because 00H – 1 = –
(01H) which is FFH in 2’s complement form. Please refer to classroom explanation
for more clarity on this. Also, do remember, DEC DPTR does not exists.
19) DEC Rr
Example: DEC R0;
Decrements the value of a RAM register. Stores the result in the same RAM
Register.
20) DEC addr
Example: DEC 25H;
Decrements the contents of a memory address.Stores the result back in the same location.
21) DEC @Rp
Example: DEC @R0;
Decrements the contents of a memory location pointed by R0.Will store the
result back at the same location
22) MUL AB
Example: MUL AB;
Multiples the 8-bit values of A register and B register. Stores the 16 bit result in
B and A Registers. B register gets the Higher Byte, A register gets the Lower
Byte
No of cycles required: 4
23) DIV AB
Example: DIV AB;
Divides the 8-bit value of A register by the 8-bit value of B register. Stores the
result in B and A Registers. B register gets the Remainder, A register gets the
Quotient
No of cycles required: 4
24) DA A
Example: DA A;
It is used when we want to add two decimal numbers (BCD numbers).
We first enter the decimal numbers, as if they are Hexadecimal. We add them by
normal ADD instruction. The answer is then adjusted using DA A instruction.
DA A always works on A Register only.
It first checks the Lower nibble of A Register.
If Lower nibble is > 9 or Aux Carry is 1, then ADD 06H
It then checks the Higher nibble of A Register.
If Higher nibble is > 9 or Carry Flag is 1, then ADD 60H
The final answer will be stored in A and Carry flag.
Note: Please get this clear, “DA A does not convert any number from Hexadecimal to
Decimal”. It simply makes the addition work like decimal addition.
DA A can only be used “After performing an Addition” operation.
0 Comments