MICROPROCESS OR 8085 Arithmetic Operations
A RITHMETIC RITHMETIC OPERATIONS Arithmetic Operations Related to Registers
The
8085 Microprocessor Microprocessor performs various arithmetic operations such as Addition, Subtraction, Increment and decrement. These operations have the following mnemonics:1. ADD : Add 2. ADI : Add Immediate 3. SUB : Subtract 4. SUI : Subtract Immediate
1
ADD R: A DD DD REGI GIS STER TO A CCUMULATOR CCUMULATOR T
he contents of the register is
added to the contents of the accumulator and the result is stored in the accumulator.
It is a one byte instruction. i nstruction.
It belongs to the register 2
addressing modes.
EXAMPLE: 51H is stored in register B and the accumulator contains 47H.Add 47H.Add the contents of B to accumulator A. Mem Address
Opcode
Operand
Hex. Code
80 00
MVI
B,51H
06,51
80 02
MVI
A,47H
3E,47
80 04
ADD
B
80
80 05
HLT
76
E XPLANATION: 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: Regist Registers ers conte contents nts before before instru instructi ction on
A
47
X
B
51
X
Flags C
Registe Registers rs conte contents nts after after instru instructi ction on
A 98 B
S
Z
1
0
AC P 0 X
0
CY 0
Flags C
3
ADI: A DD DD IMM MMED EDIA IAT TE TO A CCUMULATOR CCUMULATOR T
he 8-bit data are added to
the contents of the accumulator and the result is stored in the accumulator.
It is a two byte b yte instruction.
It belongs to the Immediate addressing modes.
4
EXAMPLE: The accumulator contains 4AH.Add the data byte 59H to the contents accumulator A. Mem Address
Opcode
Operand
Hex. Code
80 00
MVI
A,4AH
3E,4A
80 02
ADI
59H
C6,59
80 04
HLT
76
E XPLANATION: 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: Regist Registers ers conte contents nts befor before e instruc instructio tion n
A
4A
X
Flags
Regist Registers ers con conten tents ts after after instruc instructio tion n
A A3
S
Z
1
0
AC P CY 1 1 0 Flags 5
SUB R: SUBTRACT REGISTER FROM A CCUMULATOR CCUMULATOR T
he contents of the register is
subtracted from the contents of the accumulator and the result is stored in the accumulator.
It is a one byte instruction. i nstruction.
It belongs to the register addressing modes.
6
SUI: SUBTRACT IMM MMED EDIA IATE TE FR FROM OM A CCUMULATOR CCUMULATOR T
he 8-bit data are subtracted
from the contents of the accumulator and the result is stored in the accumulator.
It is a two byte b yte instruction.
It belongs to the Immediate 7
addressing modes.
EXA XAMP MPLE LE FO FOR R SUB:
Register B has 65H and the accumulator contains 97H.Subtract the contents of B from the contents of the accumulator A. Mem Address
Opcode
Operand
Hex. Code
80 00
MVI
A,97H
3E,97
80 02
MVI
B,65H
06,65
80 04
SU B
B
90
80 05
HLT
76
EXA XAMP MPLE LE FO FOR R SUI: The accumulator contains 97H.Subtract the data byte 65H from the contents accumulator A. Mem Address
Opcode
Operand
Hex. Code
8000
MVI
A,97H
3E,97
8002
SUI
65H
D6,65
8004
HLT
76
8
E XPLANATION: STEP 1:
Subtrahend (B) : 1·s compliment of (Substitute 0 for 1 and 1 for 0)
65H = 0 1 1 0 0 1 0 1 65H = 1 0 0 1 1 0 1 0 +
STEP 2:
Add 01 to obtain 2·s compliment of 65H
+
To Subtra Subtract ct : 97H ² 65H
STEP 3:
Add 97H to 2·s compliment of 65H
STEP 4:
0000 0001 9BH = 1 0 0 1 1 0 1 1
97H = 1 0 0 1 0 1 1 1 11 11 1 CY
Complement Carry Result (A) : 32H
1 0011 0010 0 0011 0010
FLAG STATUS: Regi Re gist ster ers s co conten ntents ts bef befor ore e ins instr truc ucti tio on
Reg Re giste isters rs cont conten ents ts aft after er inst instru ruct ctio ion n
S A
97
X
B
65
X
Flags C
A 32 B
65
0
Z
0
AC P
1 X
0
CY
0
Flags C
9
INR: INCREMENT CONTENTS OF REGI GIS STER BY 1 T
he 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 10
addressing modes.
EXAMPLE: Register D contains FFH. Specify the contents of register after Increment. Mem Address
Opcode
Operand
Hex. Code
80 00
MVI
D,FFH
16,FF
80 02
INR
D
14
80 03
HLT
76
E XPLANATION:
FFH = 1 1 1 1 1 1 1 1 +1 =0000 0001 Carry CY 1 1 1 1 1 1 1 1 ______________ Compliment Carry 00H 0 0 0 0 0 0 0 0 0 FLAG STATUS: Regist Registers ers conte contents nts before before instru instructi ction on
A X D FF
X X
Flags E
Regist Registers ers conte contents nts after after instru instructi ction on
A X D 00
S 0
Z AC P CY 1 1 0 X Flags
X
E
11
DCR: DECREMENT CONTENTS OF REGISTER BY 1 T
he 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 12
addressing modes.
EXAMPLE: decrement the contents of D that is Here we have to decrement 00H by 1 Mem Address
Opcode
Operand
Hex. Code
80 00
MVI
D,00H
16,00
80 02
DCR
D
15
80 04
HLT
76
FLAG STATUS: Registe Registers rs con conten tents ts before before inst instruc ructio tion n
A D
X
X
00
X
Flags E
Regist Registers ers con conten tents ts after after instruc instructio tion n
A X D FF
S 1
Z AC P CY 0 0 1 X Flags
X
E 13
E XPLANATION: STEP 1:
1H: 1·s compliment of : (Substitute 0 for 1 and 1 for 0)
1H = 0 0 0 0 0 0 0 1 1H = 1 1 1 1 1 1 1 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 Subtra Subtract ct : 01H ² 00H
Add 00H to 2·s compliment of 01H 00H = 0 0 0 0 0 0 0 0
D
= 1111 1111
STEP 4: Result (A) : FFH FLAG STATUS: Registe Registers rs con conten tents ts before before inst instruc ructio tion n
A D
X
X
00
X
Flags E
Regist Registers ers con conten tents ts after after instruc instructio tion n
A X D FF
S 1
Z AC P CY 0 0 1 X Flags
X
E
14
A RITHMETIC RITHMETIC OPERATIONS RELATED TO MEMORY The
arithmetic operations related to memory performs two tasks: Copy a data byte from memory to I. the Microprocesso M icroprocessor. r. II. Perform arithmetic operations. These instructions(other than INR and DCR) implicitly assume that one of the operands is (A); after an operation, the previous contents of the accumulator is replaced by the result. These operations have 15 the following mnemonics:-
ADD M: A DD DD MEMORY TO A CCUMULATOR CCUMULATOR T
he contents of the memory is
added to the contents of the accumulator and the result is stored in the accumulator. T
he memory location is specified
by the contents of HL register pairs.
It is a one one b te ins insttruct ructio ion. n.
16
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
80 00
LXI
H,2050H
21,50,20
80 03
ADD
M
86
80 04
HLT
76
E XPLANATION: (A) 76H = 0 1 1 1 0 1 1 0 (2050H)mem A2H = 1 0 1 0 0 0 1 0 CY 1 18H = 1 0 0 0 1 1 0 0 0 FLAG STATUS: Memo Memory ry cont conten ents ts befo before re inst instru ruct ctio ion n
Memo Memory ry cont conten ents ts afte after r inst instru ruct ctio ion n
S
Z
AC P
CY
A
76
X
Flags
A 18
B D
X
X
C
B X
X
C
X
X
E
D X
X
E
H
20
50
L
H 20
50
L
0
0
0
1
1
Flags
17
SUB M: SUBTRACT MEMORY FROM A CCUMULATOR CCUMULATOR T
he contents of the memory are
subtracted from the contents of the accumulator and the result is stored in the accumulator. T
he memory location is specified
by the contents of HL register pairs.
It is a one one b te ins insttruct ructio ion. n.
18
EXAMPLE:
Mem. Mem.lo loca cati tion on 2050H has 7FH and the accumulator has c ontents of 98H.Subtract the contents of memory from the contents the accumulator. Mem Address
Opcode
Operand
Hex. Code
80 00
LXI
H,2050H
21,50,20
80 03
SU B
M
96
80 04
HLT
76
FLAG STATUS: Memo Memory ry cont conten ents ts befo before re inst instru ruct ctio ion n
Memo Memory ry cont conten ents ts afte after r inst instru ruct ctio ion n
S
Z
AC P
CY
A
98
X
Flags
A 19
B D
X
X
C
B X
X
C
X
X
E
D X
X
E
H
20
50
L
H 20
50
L
0
0
0
0
0
Flags
19
E XPLANATION: STEP 1:
Subtrahend (2050H) : 1·s compliment of : (Substitute 0 for 1 and 1 for 0)
7FH = 0 1 1 1 1 1 1 1 7FH = 1 0 0 0 0 0 0 0 +
STEP 2:
Add 01 to obtain 2·s compliment of 7FH
STEP 3:
0000 0001 81H = 1 0 0 0 0 0 0 1 +
To Subtra Subtract ct : 98H ² 7FH Add 98H to 2·s compliment of 7F 98H
STEP 4:
=1001 1000 1 0001 1001
CY 0 0 0 0 1 1 0 0 1
Complement Carry Result (A) : 19H
FLAG STATUS: Memory contents before instruction
Memory contents after instruction
S
Z
AC P
CY 0 0 Flags
A
98
X
Flags
A 19
B D
X
X
C
B X
X
C
X
X
E
D X
X
E
H
20
50
L
H 20
50
L
0
0
0
20
ONTE TENT NTS S OF MEMORY BY 1 INR M: INCREMENT CON
he contents of the designated memory are incremented by 1 and the result is stored in the same place. It is a one byte instruction. i nstruction. It belongs to indirect addressing mode. S, Z, P, AC are modified to reflect the result of the operation. CY is 21 not modified. T
EXAMPLE: Increment the memory location 207 5H which holds 7FH.Assume HL HL register contains 2075H. Mem Address
Opcode
Operand
Hex. Code
80 00
MVI
M,7FH
36,7F
80 02
LXI
H,2075H
21,75,20
80 05
INR
M
34
80 06
HLT
76
Memory contents before instruction
H
20
75
L
Memory
2074 2075 2076
7F 22
E XPLANATION:
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 co contents be before in instruction
20
H
75
L
Memory co contents af after in instruction
Memory
20
H
75
2074 2075
L
Memory
2074 7F
2075
2076
80
2076
FLAG STATUS: Memo Memory ry cont conten ents ts befo before re inst instru ruct ctio ion n
A
X
X
Flags
B
X
X
D
X
X
C E
H
20
75
L
Memo Memory ry cont conten ents ts afte after r inst instru ruct ctio ion n
A X B X
S 1
Z AC P CY 0 1 0 X Flags
X
C
D X
X
E
H 20
75
L
23
DCR M: DECREMENT CONTENTS OF MEMORY BY 1
he contents of the designated memory are decremented by 1 and the result is stored in the same place. It is a one byte instruction. i nstruction. It belongs to indirect addressing mode. S, Z, P, AC are modified to reflect the result of the operation. CY is 24 not modified. T
EXAMPLE: Decrement the memory location 20 85H which holds A0H.Assume HL register contains 20 85H. Mem Address
Opcode
Operand
Hex. Code
80 00
MVI
M,A0H
36,A0
80 02
LXI
H,2085H
21,85,20
80 05
DCR
M
34
80 06
HLT
Memory contents before instruction
H
20
85
L Memory 2084 2085 2086
76
Memory contents after instruction
H
20
85
L
Memory
2084
A0
2085
9F
2086
25
E XPLANATION: STEP 1:
1H: 1·s compliment of : (Substitute 0 for 1 and 1 for 0)
1H = 0 0 0 0 0 0 0 1 1H = 1 1 1 1 1 1 1 0 +
STEP 2:
Add 01 to obtain 2·s compliment of 01H
0000 0001 FFH = 1 1 1 1 1 1 1 1 +
STEP 3: STEP 4:
Add A0H to 2·s compliment compliment of 01H A0H = 1 0 1 0 0 0 0 0
1 1001 1111
Complement Carry Result (M) : 9FH
9F = 1 0 0 1 1 1 1 1
FLAG STATUS: Memo Memory ry cont conten ents ts befo before re inst instru ruct ctio ion n
A
X
X
Flags
B
X
X
D
X
X
C E
H
20
85
L
Memo Memory ry cont conten ents ts afte after r inst instru ruct ctio ion n
A X B X
S 1
Z AC P CY 0 0 1 X Flags
X
C
D X
X
E
H 20
85
L
26
RITHMETIC OPERATIONS RELATED TO A RITHMETIC 16-BIT OR REGISTER PAIRS
INX: INCREMENT REGISTER
The
PAIR BY 1
contents of the specified
register pair is incremented by 1.
It treats the contents of two register pairs as one 16-bit number and increases the
27
EXAMPLE:
Register pair HL contains 9FFFH.Specify the the contents of the register if it is incremented by 1. Mem Address
Opcode
Operand
Hex. Code
80 00
LXI
H,9FFFH
21,FF,9F
80 03
INX
H
23
80 04
HLT
76
E XPLANATION:
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 A000H = 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0
Memory contents before instruction
H
9F
FF
L
Memory contents after instruction
H
A0
00
L
28
DNX: DECREMENT REGISTER PAIR BY 1 T
he contents of the specified
register pair is decremented by 1.
It treats the contents of two register pairs as one 16-bit number and decreases the contents by 1.
29
EXAMPLE:
Register pair HL contains 2000H.Specify the contents of the register if it is decremented by 1. Mem Address
Opcode
Operand
Hex. Code
80 00
LXI
H,2000H
21,00,20
80 03
DCX
H
2B
80 04
HLT
Memory contents before instruction
H
20
00
L
76
Memory contents after instruction
H
1F
FF
L
30
E XPLANATION: STEP 1: 1H: 1H = 1·s compliment of : 1H = (Substitute 0 for 1 and 1 for 0)
0000 0000 0000 0001 1111 1111 1111 1110
+ STEP 2:
Add 01 to obtain 2·s compliment of 01H
2·s compliment of 01H
STEP 4:
Complement Carry Result (A) : 1FFFH
20
00
2000H = 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 CY = 1 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1FFF = 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1
Memory contents before instruction
H
FFFFH = +
Add 2000H to
STEP 3:
00 00 00 00 00 00 0 00 1 1111 1111 1111 1111
L
Memory contents after instruction
H
1F
FF
L 31