ARITHMETIC INSTRUCTION


instructions, which are used to perform arithmetic operations such as addition, subtraction, increment or decrement of the content of a register or memory. the result is stored in the accumulator.

Opcode Operand Description
ADD R
M
Add register or memory to accumulator
ADC R
M
Add register or memory to accumulator with carry
ADI 8-bit data Add immediate to accumulator
ACI 8-bit data Add immediate to accumulator with carry
DAD Register pair Add register pair to H-L pair
SUB R
M
Subtract register or memory from accumulator
SBB R
M
Subtract register or memory from accumulator with borrow
SUI 8-bit data Subtract immediate from accumulator
SBI 8-bit data Subtract immediate from accumulator with borrow
INR R
M
Increment register or memory by 1
INX Register pair Increment register pair by 1
DCR R
M
Decrement register or memory by 1
DCX Register pair Decrement register pair by 1
DAA None Decimal adjust accumulator

1) ADD instruction:

(i) ADD reg

where reg = A, B, C, D, E, H or L

It adds the content stored in given register with the accumulator. The result of this addition is stored in accumulator.All the flags are affected with this instruction. For example A = 10101111(AF H), E = 10110101(B5 H), CY = 0 , S = 1, Z = 0 and P = 1,

ADD E

after execution of ADD E instruction A = 01100100(64 H), CY = 1 , S = 0, Z = 0, P = 0.

(ii) ADD M

It adds the content of memory location whose address is given in H-L register pair with the accumulator and the answer is stored in accumulator. For example A = 40 H H = 21 H L = 00 H, M2100 = 3A H

ADD M

after execution of the instruction ADD M will produce the result A = 7A H.

Operand Bytes Flags Affected M-Cycles T-States
Register 1 All 1 4
Memory 1 All 2 7

2) ADC instruction:

This is mnemonic for Add with carry. It adds the content stored in given register or memory location whose address is given in H-L register pair and content of CY flag with the content of accumulator. The result of this addition is stored in accumulator. All the flags are affected with this instruction

[A] < - [A] + [reg] or [MHL] + [CY ]

For example A = 50 H, CY = 1, H = 25 H, L = 00 H,M2100 = 3B H,

ADC M

after execution of the instruction ADC M will produce the result:A = 8C.

Operand Bytes Flags Affected M-Cycles T-States
Register 1 All 1 4
Memory 1 All 2 7

3) ADI instruction:

This is mnemonic for Adds immediately the data. It immediately adds the given 8-bit data with the accumulator and the answer will be stored in Accumulator.This is a two-byte instruction. All flags will be affected with this instruction.

[A] < - [A] + data

For example A = 50 H, after execution of ADI 3AH will produce the result:A = 8A H.

Operand Bytes Flags Affected M-Cycles T-States
8-bit data 2 All 2 7

4) ACI instruction:

This is mnemonic for Adds immediately the data with Carry. It immediately adds the given 8-bit data to the accumulator with carry and the answer will be stored in Accumulator. This is a two-byte instruction. All flags will be affected with this instruction.

[A] < - [A]+ data +CY

For example A = 50 H,CY = 1 after execution of ACI 3AH will produce the result:A = 8B H. if CY = 0 then result: 8A H.

Operand Bytes Flags Affected M-Cycles T-States
8-bit data 2 All 2 7

5) DAD instruction:

The format for this instruction is DAD rp

where rp = BC,DE,HL

This is mnemonic for Double Add. This instruction adds the contents of given register pair with the contents of H-L register pair. The answer will be stored in H-L register pair. Only carry flag will be affected in this instruction.

For example D = 2A H, E = B6 H, H = 01 H, L = 27 H,

DAD D

After the execution of this instruction we H = 2B H, L = DD H.

[HL] < - [HL]+ [rp]

Operand Bytes Flags Affected M-Cycles T-States
Register pair 1 Only CY 3 10

6) SUB instruction:

(i) SUB reg

where reg = A, B, C, D, E, H or L

It subtracts the contents stored in given register from the accumulator. The result of this subtraction is stored in accumulator. All flags will be affected as per the accumulator contents. The Carry flag is set, when the unsigned value subtracted is greater than the unsigned value it is subtracted from.

For example A = 10101111(AF H), D = 10110101(B5 H), CY = 0 , S = 1, Z = 0 and P = 1,

SUB D

after the execution of the instruction SUB D we get the following result:CY = 1,A = 11111010

(ii) SUB M

This instruction is one byte instruction and subtracts the contents of memory location whose address is given in H-L register pair from the accumulator and the answer is stored in accumulator.

For example A = 56 H, H = 22 H, L = 01 H and M2201 = 2C H,

SUB M

after execution of the instruction SUB M will produce the result:A = 2A H.

Operand Bytes Flags Affected M-Cycles T-States
Register 1 All 1 4
Memory 1 All 2 7

7) SBB instruction:

This instruction subtracts the contents stored in given register or memory location addressed by H-L register pair with borrow bit (carry flag) from accumulator. The answer will be stored in accumulator.All the flags are affected in the operation of this instruction.The Carry flag is set, when the unsigned value subtracted is greater than the unsigned value it is subtracted from. The possible combinations of this instruction are as given below:

SBB reg       (Subtract with Borrow)

SBB M      (Subtract memory with Borrow)

[A] < - [A] - [reg / MHL] - [CY]

For example A = 10101111, H = 10110101, CY = 0 , S = 1, Z = 0 and P = 1,

SBB H

after the execution of the instruction SBB H we get the following result:A = 11111001, CY = 1.

Operand Bytes Flags Affected M-Cycles T-States
Register 1 All 1 4
Memory 1 All 2 7

8) SUI instruction:

It immediately subtracts the given 8-bit data with the accumulator contents and the answer will be stored in Accumulator.The 8-bit data is subtracted from the contents of the accumulator. The Carry flag is set, when the unsigned value subtracted is greater than the unsigned value it is subtracted from.

For example A = 50 H,

SUI 45H

after the execution of the instruction SUI 45H we get the A = 05H.

Operand Bytes Flags Affected M-Cycles T-States
8-bit data 2 All 2 7

9) SBI instruction:

SBI data instruction subtracts the given 8-bit data with borrow bit (carry flag) from the accumulator contents and it stores the answer in accumulator.The Carry flag is set, when the unsigned value subtracted is greater than the unsigned value it is subtracted from.

For example A = 50H,

SBI 45H

after the execution of the instruction SBI 45H if CY = 0 then we get the A = 05H.if CY = 1 then A = 04H.

[A] < - [A] - [8-bit data] - [CY]

Operand Bytes Flags Affected M-Cycles T-States
8-bit data 2 All 2 7

10) INR instruction:

It increments the contents of memory location addressed by H-L register pair or contents of given register by 1 and stores the answer in the addressed memory location or given register.all flags except carry flag will be affected after the execution of this instruction. The possible combinations of this instruction are as given below:

INR reg      (Increment Register)

INR M      (Increment Memory)

For example H = 22 H,

INR H

after the execution of the instruction INR H we get the H = 23 H.

Operand Bytes Flags Affected M-Cycles T-States
Register 1 All,except CY 1 4
Memory 1 All,except CY 3 10

11) INX instruction:

INX rp instruction increments the contents given in register pair by one and the result is stored in the given register pair.No flag is affected with the execution of this instruction.

[rp] < - [rp] + 1

where rp = BC,DE,HL

For example H = 21 H, L = 02 H,

INX H

after the execution of the instruction INX H we get the H = 21 H, L = 03H.

Operand Bytes Flags Affected M-Cycles T-States
Register pair 1 None 1 6

12) DCR instruction:

It decrements the contents of memory location addressed by H-L register pair or contents of given register by 1 and stores the answer in the addressed memory location or given register.all flags except carry flag will be affected after the execution of this instruction. The possible combinations of this instruction are as given below:

DCR reg      (Decrement Register)

DCR M      (Decrement Memory)

For example H = 22 H,

DCR H

after the execution of the instruction DCR H we get the H = 21 H.

Operand Bytes Flags Affected M-Cycles T-States
Register 1 All,except CY 1 4
Memory 1 All,except CY 3 10

DCX instruction:

DCX rp instruction decrements the contents given in register pair by one and the result is stored in the given register pair.No flag is affected with the execution of this instruction.

[rp] < - [rp] - 1

where rp = BC,DE,HL

For example H = 21 H, L = 02 H,

DCX H

after the execution of the instruction DCX H we get the H = 21 H, L = 01H.

Operand Bytes Flags Affected M-Cycles T-States
Register pair 1 None 1 6

14) DAA instruction:

The DAA is one byte instruction and no operand is needed with this instruction. It adjusts the accumulator to packed BCD (Binary Coded Decimal) after addition of two BCDs. In other words, after addition of two hexadecimal numbers if this instruction is used then the result in decimal form is obtained. For this Auxiliary Carry Flag (AC) and Carry Flag (CY) take care of this instruction.It functions in two steps:

1) If the lower nibble (lower 4-bits) of the accumulator is greater than 9 or Auxiliary carry flag is set, then it adds 06 H to the accumulator.

2) Subsequently, if the higher nibble (higher 4-bits) of the accumulator is now greater than 9 or the carry flag (CY) is set, it adds 60 H to the accumulator.

Operand Bytes Flags Affected M-Cycles T-States
None 1 All 1 4

For example A = 38 H,

ADI 87H

DAA

after the execution of above instruction, A = 0 0 1 0 0 1 0 1, CY = 1, AC = 1.

Explanation,

A = 38 H,    0 0 1 1 1 0 0 0

Adds 87 H, 1 0 0 0 0 1 1 1

----------------------------------

       1 0 1 1 1 1 1 1  Lower 4-bits

       0 0 0 0 0 1 1 0  is > 9

----------------------------------

       1 1 0 0 0 1 0 1  AC = 1

       0 1 1 0 0 0 0 0  Upper 4-bits

----------------------------------  is > 9

    1 0 0 1 0 0 1 0 1