Top Banner
MICROPROCESS OR 8085 Arithmetic Operations
33

Arithmetic Operations in Microprocessor 8085

Nov 21, 2014

Download

Documents

Unique Moh'd
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Arithmetic Operations in Microprocessor 8085

MICROPROCESSOR 8085Arithmetic Operations

Page 2: Arithmetic Operations in Microprocessor 8085

ARITHMETIC OPERATIONSArithmetic Operations Related to Registers

The 8085 Microprocessor performs various arithmetic operations such as Addition, Subtraction, Increment and decrement. These operations have the following mnemonics:-1.ADD : Add2.ADI : Add Immediate3.SUB : Subtract4.SUI : Subtract Immediate5.INR : Increment6.DCR : Decrement

1

Page 3: Arithmetic Operations in Microprocessor 8085

ADD R: ADD REGISTER TO ACCUMULATOR

2

The 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.It belongs to the register addressing modes.

All flags are modified to reflect the result of addition

Page 4: Arithmetic Operations in Microprocessor 8085

51H is stored in register B and the accumulator contains 47H.Add the contents of B to accumulator A.

Mem Address Opcode Operand Hex. Code8000 MVI B,51H 06,518002 MVI A,47H 3E,478004 ADD B 808005 HLT 76

EXAMPLE:

EXPLANATION:47H = 0 1 0 0 0 1 1 151H = 0 1 0 1 0 0 0 198H = 1 0 0 1 1 0 0 0

FLAG STATUS:

47

X

51

X

AB C

Flags AB C

Flags98

1 0 0 0 0

X

S Z AC P CYRegisters contents before

instructionRegisters contents after instruction

3

Page 5: Arithmetic Operations in Microprocessor 8085

ADI: ADD IMMEDIATE TO ACCUMULATOR

The 8-bit data are added to the contents of the accumulator and the result is stored in the accumulator.

It is a two byte instruction.It belongs to the Immediate addressing modes.

All flags are modified to reflect the result of addition

4

Page 6: Arithmetic Operations in Microprocessor 8085

The accumulator contains 4AH.Add the data byte 59H to the contents accumulator A.

Mem Address Opcode Operand Hex. Code8000 MVI A,4AH 3E,4A8002 ADI 59H C6,598004 HLT 76

EXAMPLE:

EXPLANATION:4AH = 0 1 0 0 1 0 1 059H = 0 1 0 1 1 0 0 1A3H = 1 0 1 0 0 0 1 1

FLAG STATUS:

4A

XA Flags A FlagsA3

1 0 1 1 0S Z AC P CY

Registers contents before instruction

Registers contents after instruction

5

Page 7: Arithmetic Operations in Microprocessor 8085

SUB R: SUBTRACT REGISTER FROM ACCUMULATOR

The 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.It belongs to the register addressing modes.All flags are modified to reflect the result of subtraction.

6

Page 8: Arithmetic Operations in Microprocessor 8085

SUI: SUBTRACT IMMEDIATE FROM ACCUMULATOR

The 8-bit data are subtracted from the contents of the accumulator and the result is stored in the accumulator.

It is a two byte instruction.It belongs to the Immediate addressing modes.

All flags are modified to reflect the result of subtraction.

7

Page 9: Arithmetic Operations in Microprocessor 8085

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. Code8000 MVI A,97H 3E,978002 MVI B,65H 06,658004 SUB B 908005 HLT 76

EXAMPLE FOR SUB:

8

The accumulator contains 97H.Subtract the data byte 65H from the contents accumulator A.

Mem Address Opcode Operand Hex. Code8000 MVI A,97H 3E,978002 SUI 65H D6,658004 HLT 76

EXAMPLE FOR SUI:

Page 10: Arithmetic Operations in Microprocessor 8085

EXPLANATION:

65H = 0 1 1 0 0 1 0 165H = 1 0 0 1 1 0 1 0

Subtrahend (B) :

STEP 1:1’s compliment

of (Substitute 0 for 1 and 1 for 0)

0 0 0 0 0 0 0 19BH = 1 0 0 1 1 0 1 197H = 1 0 0 1 0 1 1 1 1 1 1 1 1 0 0 1 1 0 0 1 0

0 0 1 1 0 0 1 0

+

+

Add 01 to obtain 2’s compliment of

65H To Subtract : 97H – 65HAdd 97H to 2’s compliment of

65H

1CY

0STEP 4:

STEP 3:

STEP 2:

Complement Carry Result (A) : 32H

9

FLAG STATUS:

97

X

65

X

AB C

Flags AB C

FlagsS Z AC P CY

Registers contents before instruction

Registers contents after instruction

32

0 0 1 0 0

65

X

Page 11: Arithmetic Operations in Microprocessor 8085

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

Page 12: Arithmetic Operations in Microprocessor 8085

Register D contains FFH. Specify the contents of register after Increment.

Mem Address Opcode Operand Hex. Code8000 MVI D,FFH 16,FF8002 INR D 148003 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 ______________00H 0 0 0 0 0 0 0 0

FLAG STATUS:

X XFF X

AD E

Flags AD E

FlagsS Z AC P CY

Registers contents before instruction

Registers contents after instruction

1

0

X 0 1 1 0 X00

X

EXAMPLE:

Carry

Compliment Carry

11

Page 13: Arithmetic Operations in Microprocessor 8085

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

Page 14: Arithmetic Operations in Microprocessor 8085

Here we have to decrement the contents of D that is 00H by 1

Mem Address Opcode Operand Hex. Code8000 MVI D,00H 16,008002 DCR D 158004 HLT 76

EXAMPLE:

FLAG STATUS:Registers contents before

instructionRegisters contents after instruction

X X00 X

AD E

Flags AD E

FlagsS Z AC P CY

X 1 0 0 1 XFF X

13

Page 15: Arithmetic Operations in Microprocessor 8085

EXPLANATION:

1H = 0 0 0 0 0 0 0 11H = 1 1 1 1 1 1 1 0

1H: STEP 1:1’s compliment

of : (Substitute 0 for 1 and 1 for 0)

0 0 0 0 0 0 0 1FFH = 1 1 1 1 1 1 1 1

00H = 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1

+

+

Add 01 to obtain 2’s compliment of

01H

D =

STEP 4:

STEP 3:

STEP 2:

Result (A) : FFH

To Subtract : 01H – 00HAdd 00H to 2’s compliment of

01H

14

FLAG STATUS:Registers contents before

instructionRegisters contents after instruction

X X00 X

AD E

Flags AD E

FlagsS Z AC P CY

X 1 0 0 1 XFF X

Page 16: Arithmetic Operations in Microprocessor 8085

ARITHMETIC OPERATIONS RELATED TO MEMORYThe arithmetic operations related to memory performs two tasks:I.Copy a data byte from memory to the Microprocessor.II.Perform arithmetic operations.These instructions(other than INR and DCR) implicitly assume thatone of the operands is (A); after an operation, the previous contentsof the accumulator is replaced by the result. These operations havethe following mnemonics:-1.ADD : Add2.SUB : Subtract3.INR : Increment4.DCR : Decrement

15

Page 17: Arithmetic Operations in Microprocessor 8085

ADD M: ADD MEMORY TO ACCUMULATORThe 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.All flags are affected to reflect the result of addition. 16

Page 18: Arithmetic Operations in Microprocessor 8085

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. Code8000 LXI H,2050H 21,50,208003 ADD M 868004 HLT 76

EXAMPLE:

EXPLANATION:76H = 0 1 1 1 0 1 1 0A2H = 1 0 1 0 0 0 1 018H = 0 0 0 1 1 0 0 0

FLAG STATUS:

76 XX XX X20 50

A

L

CFlags A

B CFlags

S Z AC P CYMemory contents before instruction Memory contents after instruction

11CY(2050H)mem

(A)

18

0 0 0 1 1

X XX X20

50

DH

DH

EB

EL 17

Page 19: Arithmetic Operations in Microprocessor 8085

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.

All flags are affected to reflect the result of subtraction.

18

Page 20: Arithmetic Operations in Microprocessor 8085

Mem.location 2050H has 7FH and the accumulator has 98H.Subtract the contents of memory from the contents of the accumulator.

Mem Address Opcode Operand Hex. Code8000 LXI H,2050H 21,50,208003 SUB M 968004 HLT 76

EXAMPLE:

FLAG STATUS:

98 XX XX X20 50

A

L

CFlags A

B CFlags

S Z AC P CYMemory contents before instruction Memory contents after instruction

19

0 0 0 0 0

X XX X20

50

DH

DH

EB

EL

19

Page 21: Arithmetic Operations in Microprocessor 8085

EXPLANATION:7FH = 0 1 1 1 1 1 1 17FH = 1 0 0 0 0 0 0 0

Subtrahend (2050H) :

STEP 1:1’s compliment

of : (Substitute 0 for 1 and 1 for 0)

0 0 0 0 0 0 0 181H = 1 0 0 0 0 0 0 1

98H = 1 0 0 1 1 0 0 0 0 0 0 1 1 0 0 1

0 0 0 1 1 0 0 1

+

+

Add 01 to obtain 2’s compliment of

7FH To Subtract : 98H – 7FHAdd 98H to 2’s compliment of

7F 1

CY 0STEP 4:

STEP 3:

STEP 2:

Complement Carry Result (A) : 19H

20

FLAG STATUS:

98 XX XX X20 50

A

L

CFlags A

B C

S Z AC P CYMemory contents before instruction

19

0 0 0 0 0

X XX X20

50

DH

DH

EB

EL

Memory contents after instruction

Flags

Page 22: Arithmetic Operations in Microprocessor 8085

INR M: INCREMENT CONTENTS OF MEMORY BY 1

The contents of the designated memory are incremented 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. 21

Page 23: Arithmetic Operations in Microprocessor 8085

Increment the memory location 2075H which holds 7FH.Assume HL register contains 2075H.

Mem Address Opcode Operand Hex. Code8000 MVI M,7FH 36,7F8002 LXI H,2075H 21,75,208005 INR M 348006 HLT 76

EXAMPLE:

22

Memory contents before instruction

20 75H L Memory

7F

2076

2075

2074

Page 24: Arithmetic Operations in Microprocessor 8085

EXPLANATION:7FH = 0 1 1 1 1 1 1 101H = 0 0 0 0 0 0 0 180H = 1 0 0 0 0 0 0 0

Result :

Incremented by 1 :

23

FLAG STATUS:

AB C

Flags AB C

FlagsS Z AC P CY

Memory contents before instruction Memory contents after instruction

X XX XX X20 75

X 1 0 1 0 XX XX X20

75LDH

DH

E EL

Memory contents before instruction Memory contents after instruction

20 75H L Memory

7F

20 75H L Memory

80

2076

2075

2074

2076

2075

2074

Page 25: Arithmetic Operations in Microprocessor 8085

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

Page 26: Arithmetic Operations in Microprocessor 8085

Decrement the memory location 2085H which holds A0H.Assume HL register contains 2085H.

Mem Address Opcode Operand Hex. Code8000 MVI M,A0H 36,A08002 LXI H,2085H 21,85,208005 DCR M 348006 HLT 76

EXAMPLE:

25

Memory contents before instruction Memory contents after instruction

Memory 20 85H L Memory

9F2086 2086

2085

208420 85H L

A02085

2084

Page 27: Arithmetic Operations in Microprocessor 8085

EXPLANATION:

1H = 0 0 0 0 0 0 0 11H = 1 1 1 1 1 1 1 0

1H: STEP 1:1’s compliment

of : (Substitute 0 for 1 and 1 for 0)

0 0 0 0 0 0 0 1FFH = 1 1 1 1 1 1 1 1A0H = 1 0 1 0 0 0 0 0 1 0 0 1 1 1 1 1

9F = 1 0 0 1 1 1 1 1

+

+

Add 01 to obtain 2’s compliment of

01H

1STEP 4:STEP 3:

STEP 2:

Complement Carry Result (M) : 9FH

Add A0H to 2’s compliment of 01H

26

FLAG STATUS:

AB C

Flags AB C

FlagsS Z AC P CY

Memory contents before instruction Memory contents after instruction

X XX XX X20 85

X 1 0 0 1 XX XX X20

85LDH

DH

E EL

Page 28: Arithmetic Operations in Microprocessor 8085

ARITHMETIC OPERATIONS RELATED TO 16-BIT OR REGISTER PAIRS

INX: INCREMENT REGISTER PAIR BY 1• The 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 contents by 1.

• It is a one byte instruction.• No flags are affected. 27

Page 29: Arithmetic Operations in Microprocessor 8085

Register pair HL contains 9FFFH.Specify the contents of the register if it is incremented by 1.

Mem Address Opcode Operand Hex. Code8000 LXI H,9FFFH 21,FF,9F8003 INX H 238004 HLT 76

EXAMPLE:

EXPLANATION:9FFFH = 1 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 01H = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1A000H = 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0

Result :

Incremented by 1 :

Memory contents before instruction Memory contents after instruction

A0 00H L9F FFH L

28

Page 30: Arithmetic Operations in Microprocessor 8085

DNX: DECREMENT REGISTER PAIR BY 1

The 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.

It is a one byte instruction.No flags are affected.

29

Page 31: Arithmetic Operations in Microprocessor 8085

Register pair HL contains 2000H.Specify the contents of the register if it is decremented by 1.

Mem Address Opcode Operand Hex. Code8000 LXI H,2000H 21,00,208003 DCX H 2B8004 HLT 76

EXAMPLE:

Memory contents before instruction Memory contents after instruction

1F FFH L20 00H L

30

Page 32: Arithmetic Operations in Microprocessor 8085

EXPLANATION:

1H = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 11H = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0

1H: STEP 1:

1’s compliment of : (Substitute 0 for 1 and 1 for

0)

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1FFFFH = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12000H = 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1

0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1

+

+

Add 01 to obtain 2’s compliment of

01H

=STEP 4:

STEP 3:

STEP 2:

Complement Carry Result (A) : 1FFFH

Add 2000H to 2’s compliment of

01H 1CY

0 1FFF =

31

Memory contents before instruction Memory contents after instruction

1F FFH L20 00H L

Page 33: Arithmetic Operations in Microprocessor 8085