Sunteți pe pagina 1din 6

1.

8 BIT ARITHMETIC OPERATIONS


Aim:
To perform 8 bit arithmetic operations like addition, subtraction, multiplication
and division using 8085 microprocessor.
Apparatus required: 8085 microprocessor kit and power supply
8 BIT ADDITION
Initialize HL register pair with a memory pointer.
Transfer the addend from the memory location to accumulator.
Increment memory pointer
Add the contents of memory location (augend) to accumulator (addend).
Increment memory pointer and store the sum
Clear the accumulator and add accumulator with carry.
Increment the memory pointer and store the carry

Step 1:
Step 2:
Step 3:
Step4:
Step 3:
Step 4:
Step 5:
Program:
Memory
Location
4100

Machine code

Label

Mnemonics

Comment

21,00,42

LXI H, 4200

Initialize HL register pair


with a memory pointer

4103

7E

MOV A, M

4104
4105

23
86

INX H
ADD M

4106
4107

23
77

INX H
MOV M, A

4108

3E, 00

MVI A, 00

Transfer the memory


contents to accumulator
Increment memory pointer
Add the contents of memory
pointer to accumulator
Increment memory pointer
Transfer the LSB of the sum
to memory location
Clear accumulator

410A

8F

ADC A

410B
410C

23
77

INX H
MOV M, A

410D

76

HLT

Add accumulator with itself


along with carry
Increment memory pointer
Transfer MSB of the sum to
memory location
End execution

Sample input and output:


Addend
[4200]

Augend
[4201]

LSB of the Sum


[4202]

MSB of the sum


[4203]

8 BIT SUBTRACTION
Step 1:
Step 2:
Step 3:
Step4:

Initialize HL register pair with a memory pointer.


Transfer the minuend from the memory location to accumulator.
Increment memory pointer
Subtract the contents of memory location (subtrahend) from accumulator
(minuend).
Increment memory pointer and store the difference.
Clear the accumulator and add accumulator with carry.
Increment the memory pointer and store the borrow

Step 3:
Step 4:
Step 5:
Program:
Memory
Location
4100

Machine code

Label

Mnemonics

Comment

21,00,42

LXI H, 4200

Initialize HL register pair


with a memory pointer

4103

7E

MOV A, M

4104
4105

23
96

INX H
SUB M

4106
4107

23
77

INX H
MOV M, A

4108

3E, 00

MVI A, 00

Transfer the memory


contents to accumulator
Increment memory pointer
Subtract the contents of
memory pointer from
accumulator
Increment memory pointer
Transfer the sum to memory
location
Clear accumulator

410A

8F

ADC A

410B
410C

23
77

INX H
MOV M, A

410D

76

HLT

Add accumulator with itself


along with carry
Increment memory pointer
Transfer borrow to memory
location
End

Sample input and output


Minuend
[4200]

Subtrahend
[4201]

Difference
[4202]

Borrow
[4203]

8 BIT MULTIPLICATION
Step 1:
Step 2:
Step 3:
Step 4:
Step 5:
Step 6:
Step 7:
Step 8:

Initialize HL register pair with a memory pointer.


Clear the accumulator and register C
Get the multiplicand to register B. If it is zero go to step 8.
Increment the memory pointer
Add accumulator with the contents of memory pointer ( i.e., multiplier)
If addition generates a carry increment register C.
Decrement register B. If it does not result zero go to step 5.
Store the contents of accumulator (LSB of the product) and the contents of
C register ( MSB of the product) in successive memory locations.

Memory
Location
4100

Machine code

Label

Mnemonics

Comment

21,00,42

LXI H, 4200

Initialize HL register pair


with a memory pointer

4103
4105
4106

3E, 00
4F
46

MVI A, 00
MOV C, A
MOV B, M

4107
4108

23
B8

4109

CA, 15 , 41

410C

86

410D

D2,11, 41

4110

0C

4111
4112
4115
4116

05
C2, 0C,41
23
77

4117
4118

23
71

4119

76

Clear accumulator
Clear C register
Get the multiplicand to
register B
INX H
Increment memory pointer
CMP B
Compare the multiplicand
with zero
JZ
LOOP3 If multiplicand is zero jump
to LOOP3
LOOP2 ADD M

Add accumulator contents


with memory contents
JNC
LOOP1 If the addition does not
generate a carry jump to
LOOP1
INR C
If carry results increment C
register
LOOP1 DCR B
Decrement register B
JNZ LOOP 2 If no zero jump to LOOP2
LOOP3 INX H
Increment memory pointer
MOV M, A
Move the contents of
accumulator to memory
location
INX H
Increment memory pointer
MOV M, C
Move contents of C register
to memory location
HLT
End execution

Sample input and output


Multiplicand
[4200]

Step 1:
Step 2:
Step 3:
Step 4:
Step 5:
Step 6:
Step 7:
Step 8:

Multiplier
[4201]

Product
LSB
[4202]

MSB
[4203]

8 BIT DIVISION
Initialize HL register pair with a memory pointer.
Clear register C.
Get the dividend to D register and divider to accumulator and B register .
Check for the divider. If the divider is zero, set the quotient and remainder
as EE, store in successive memory locations and end the program .
Else move the dividend to accumulator.
Subtract the contents of register B from accumulator.
If carry does not set increment C register and go to step 6
If carry sets, add the contents of register B to accumulator to get the
remainder, and store quotient and remainder in successive memory
locations.

Memory
Location
4100

Machine code

Label

Mnemonics

Comment

21,00,42

LXI H, 4200

Initialize HL register pair


with a memory pointer

4103

0E, 00

MVI C, 00

4105

56

4106
4107
4108
4109

23
7E
46
FE, 00

410B

CA, 23,41

410E

7A

410F

90

LOOP4 SUB

4110
4113
4114
4117

DA, 17,41
OC
C3, 0F 41
80

JC LOOP 3
INR
C
JMP LOOP4
LOOP3 ADD
B

4118
4119

23
71

Clear C register (quotient


register)
MOV D, M
Get the dividend to D
register
INX H
Increment memory pointer
MOV A, M
Get divider to accumulator
MOV B, M
Get the divider to B register
CPI,
00
Compare the divider with
zero
JZ
LOOP1 If divider is zero jump to
LOOP1
MOV A, D
B

INX H
MOV M,

Move dividend to
accumulator
Subtract the divider from
the dividend
If carry sets jump to LOOP3
Increment quotient register
Repeat subtraction
Add the contents of B to
accumulator to get the
quotient
Increment memory pointer
Store quotient in memory

411A
411B

23
77

INX H
MOV M , A

411C
411D
411E, 1F

76
23
36, EE

HLT
LOOP1 INX H
MVI M, EE

4120
4121,22

23
36, EE

INX H
MVI M, EE

4123

76

HLT

location
Increment memory pointer
Store remainder in memory
location
End execution
Increment memory pointer
Store EE in memory
location
Increment memory pointer
Store EE in memory
location
End execution

Sample input and output


Dividend
[4200]

Divider
[4201]

Quotient
[4202]

Remainder
[4203]

Result: The assembly language programs to perform 8-bit addition, subtraction,


multiplication and division are written and executed.
Questions and Answers
1. What is the clock frequency of 8085?
2. What is the function of program counter?
3. What are the general purpose registers in 8085?
4. What is the function of ALE signal in 8085?
5. What is meant by demultiplexing of address bus?
6. Give some examples for 8-bit, 16-bit and 32-bit microprocessors
7. Compare microprocessor and microcontroller.
8. What is meant by manual assembly?
9. Which part of the microprocessor decides the word length?
10. How you find the memory capacity of microprocessor? Give some examples.

Exercise
1.

2.

3.

Write a program to add the following data bytes stored in memory locations
starting at XX60H and display the sum in the location XX80H if the sum does
not generate a carry. If a result generates a carry, stop the addition, and display
01H in the location XX80H.
A set of eight data bytes are stored in memory locations starting from XX70H.
Write a program to add two data bytes at a time and store the sum in the same
memory locations, low order sum replacing the first byte and a carry replacing
the second byte. If any pair does not generate a carry, the memory location of
the second byte should be cleared.
A set of eight data bytes are stored in memory locations starting from XX70H.
Write a program to subtract two data bytes at a time and store the result in a
sequential order in memory location starting from XX70H

S-ar putea să vă placă și