Arithmetic Operations in Microprocessor 8085
Arithmetic Operations in Microprocessor 8085
8085
Arithmetic Operations
ARITHMETIC OPERATIONS
Arithmetic Operations Related to Registers
3.SUB : Subtract
5.INR : Increment
1
6.DCR : Decrement
ADD R: ADD REGISTER TO
ACCUMULATOR
2
EXAMPLE:
51H is stored in register B and the accumulator contains
47H.Add the contents of B to accumulator A.
Mem Address Opcode Operand Hex. Code
8000 MVI B,51H 06,51
8002 MVI A,47H 3E,47
8004 ADD B 80
8005 HLT 76
EXPLANATION:
47H = 0 1 0 0 0 1 1 1
51H = 0 1 0 1 0 0 0 1
98H = 1 0 0 1 1 0 0 0
FLAG STATUS:
Registers contents before instruction Registers contents after instruction
S Z AC P CY
A 47 X Flags A 98 1 0 0 0 0 Flags
B 51 X C X C 3
B
ADI: ADD IMMEDIATE TO
ACCUMULATOR
EXPLANATION:
4AH = 0 1 0 0 1 0 1 0
59H = 0 1 0 1 1 0 0 1
A3H = 1 0 1 0 0 0 1 1
FLAG STATUS:
Registers contents before instruction Registers contents after instruction
S Z AC P CY
A 4A X Flags A A3 1 0 1 1 0 Flags
5
SUB R: SUBTRACT REGISTER FROM
ACCUMULATOR
7
EXAMPLE FOR SUB:
Register B has 65H and the accumulator contains 97H.Subtract the
contents of B from the contents of the accumulator A.
CY 10 0 1 1 0 0 1 0
STEP 4: Complement Carry
Result (A) : 32H
00 0 1 1 0 0 1 0
FLAG STATUS:
Registers contents before instruction Registers contents after instruction
S Z AC P CY
A 97 X Flags A 32 0 0 1 0 0 Flags
9
B 65 X C B 65 X C
INR: INCREMENT CONTENTS OF
REGISTER BY 1
The contents of the designated register are incremented by 1
and the result is stored in the accumulator.
It is a one byte instruction.
It belongs to the register addressing modes.
S, Z, P, AC are modified to reflect the result of the operation.
CY is not modified. 10
EXAMPLE:
Register D contains FFH. Specify the contents of register after
Increment.
Mem Address Opcode Operand Hex. Code
8000 MVI D,FFH 16,FF
8002 INR D 14
8003 HLT 76
EXPLANATION:
FFH = 1 1 1 1 1 1 1 1
+1 = 0 0 0 0 0 0 0 1
CY 1 1 1 1 1 1 1 1 Carry
______________
Compliment Carry 00H 00 0 0 0 0 0 0 0
FLAG STATUS:
Registers contents before instruction Registers contents after instruction
S Z AC P CY
A X X Flags A X 0 1 1 0 X Flags
D FF X E D 00 X E 11
DCR: DECREMENT CONTENTS OF
REGISTER BY 1
The contents of the designated register are decremented by 1
and the result is stored in the accumulator.
It is a one byte instruction.
It belongs to the register addressing modes.
S, Z, P, AC are modified to reflect the result of the operation.
CY is not modified. 12
EXAMPLE:
Here we have to decrement the contents of D that is 00H by 1
FLAG STATUS:
Registers contents before instruction Registers contents after instruction
S Z AC P CY
X X Flags A X 1 0 0 1 X Flags
A
00 X E D FF X E
D
13
EXPLANATION:
STEP 1: 1H: 1H = 0 0 0 0 0 0 0 1
1’s compliment of : 1H = 1 1 1 1 1 1 1 0
(Substitute 0 for 1 and 1 for 0)
+
STEP 2: Add 01 to obtain
0000 0001
2’s compliment of 01H FFH = 1 1 1 1 1 1 1 1
+
STEP 3: To Subtract : 01H – 00H
Add 00H to 2’s compliment of 01H 00H = 0 0 0 0 0 0 0 0
D =1111 1111
FLAG STATUS:
Registers contents before instruction Registers contents after instruction
S Z AC P CY
A X X Flags A X 1 0 0 1 X Flags
14
D 00 X E D FF X E
ARITHMETIC OPERATIONS RELATED TO
MEMORY
2.SUB : Subtract
3.INR : Increment 15
4.DCR : Decrement
ADD M: ADD MEMORY TO ACCUMULATOR
The contents of the memory is added to the contents of the
accumulator and the result is stored in the accumulator.
The memory location is specified by the contents of HL register
pairs.
It is a one byte instruction.
It belongs to indirect addressing mode.
16
All flags are affected to reflect the result of addition.
EXAMPLE:
Mem.location 2050H has A2H and the accumulator has 76H.Add the contents
of memory to the contents of the accumulator.
Mem Address Opcode Operand Hex. Code
8000 LXI H,2050H 21,50,20
8003 ADD M 86
8004 HLT 76
EXPLANATION:
(A) 76H = 0 1 1 1 0 1 1 0
(2050H)mem A2H = 1 0 1 0 0 0 1 0
CY 1 18H = 10 0 0 1 1 0 0 0
FLAG STATUS:
Memory contents before instruction Memory contents after instruction
S Z AC P CY
A 76 X Flags A 18 0 0 0 1 1 Flags
B X X C B X X C
D X X E D X X E
H 20 50 L H 20 50 L 17
SUB M: SUBTRACT MEMORY FROM
ACCUMULATOR
The contents of the memory are subtracted from the contents of
the accumulator and the result is stored in the accumulator.
The memory location is specified by the contents of HL register
pairs.
It is a one byte instruction.
It belongs to indirect addressing mode.
18
All flags are affected to reflect the result of subtraction.
EXAMPLE:
Mem.location 2050H has 7FH and the accumulator has 98H.Subtract
the contents of memory from the contents of the accumulator.
FLAG STATUS:
Memory contents before instruction Memory contents after instruction
S Z AC P CY
A 98 X Flags A 19 0 0 0 0 0 Flags
B X X C B X X C
D X X E D X X E
H 20 50 L H 20 50 L
19
EXPLANATION:
STEP 1: Subtrahend (2050H) : 7FH = 0 1 1 1 1 1 1 1
1’s compliment of : 7FH = 1 0 0 0 0 0 0 0
(Substitute 0 for 1 and 1 for 0)
+
STEP 2: Add 01 to obtain 0000 0001
2’s compliment of 7FH 81H = 1 0 0 0 0 0 0 1
H 20 75 L Memory
2074
2075 7F
2076
22
EXPLANATION:
7FH = 0 1 1 1 1 1 1 1
Incremented by 1 : 01H = 0 0 0 0 0 0 0 1
Result : 80H = 1 0 0 0 0 0 0 0
Memory contents before instruction Memory contents after instruction
H 20 75 L Memory H 20 75 L Memory
2074 2074
2075 7F 2075 80
2076 2076
FLAG STATUS:
Memory contents before instruction Memory contents after instruction
S Z AC P CY
A X X Flags A X 1 0 1 0 X Flags
B X X C B X X C
D X X E D X X E
H 20 75 L H 20 75 L 23
DCR M: DECREMENT CONTENTS OF
MEMORY BY 1
The contents of the designated memory are decremented by 1
and the result is stored in the same place.
It is a one byte instruction.
It belongs to indirect addressing mode.
S, Z, P, AC are modified to reflect the result of the operation. CY
is not modified.
The memory location is specified by the contents of the HL
register pairs.
24
EXAMPLE:
Decrement the memory location 2085H which holds
A0H.Assume HL register contains 2085H.
Mem Address Opcode Operand Hex. Code
8000 MVI M,A0H 36,A0
8002 LXI H,2085H 21,85,20
8005 DCR M 34
8006 HLT 76
H 20 85 L Memory H 20 85 L Memory
2084 2084
2085 A0 2085 9F
2086 2086
25
EXPLANATION:
STEP 1: 1H: 1H = 0 0 0 0 0 0 0 1
1’s compliment of : 1H = 1 1 1 1 1 1 1 0
(Substitute 0 for 1 and 1 for 0)
+
STEP 2: Add 01 to obtain 0000 0001
2’s compliment of 01H FFH = 1 1 1 1 1 1 1 1
+
STEP 3: Add A0H to 2’s compliment of 01H A0H = 1 0 1 0 0 0 0 0
STEP 4: Complement Carry
11001 1111
Result (M) : 9FH 9F = 1 0 0 1 1 1 1 1
FLAG STATUS:
Memory contents before instruction Memory contents after instruction
S Z AC P CY
A X X Flags A X 1 0 0 1 X Flags
B X X C B X X C
D X X E D X X E
20 85 L 26
H H 20 85 L
ARITHMETIC OPERATIONS RELATED
TO 16-BIT OR REGISTER PAIRS
INX: INCREMENT REGISTER PAIR BY 1
EXPLANATION:
9FFFH = 1 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1
Incremented by 1 : 01H = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
Result : A000H = 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0
H 9F FF L H A0 00 L
28
DNX: DECREMENT REGISTER PAIR BY 1
H 20 00 L H 1F FF L
30
EXPLANATION:
STEP 1:
1H: 1H = 0000 0000 0000 0001
1’s compliment of : 1H = 1111 1111 1111 1110
(Substitute 0 for 1 and 1 for 0)
+
STEP 2: Add 01 to obtain 0000 0000 0000 0001
2’s compliment of 01H FFFFH = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
H 20 00 L H 1F FF L
31