You are on page 1of 15

4 a.

AVERAGE OF N NUMBERS
AIM:
To write an assembly language program that finds the average of N numbers and
executes the program using 8085 microprocessor kit.
APPARATUS REQUIRED:
8085 microprocessor kit, power supply.
ALGORITHM:
STEP 1: Load HL register pair with a memory pointer.
STEP 2: Get the count to B register and push the count to stack pointer.
STEP 3: Clear accumulator, D and E registers.
STEP 4: Increment memory pointer.
STEP 5: Add the content of memory location to accumulator.
STEP 6: If carry results increment D register.
STEP 7: Decrement count. If it is not zero go to STEP 4.
STEP 8: Else move the sum to E register.
STEP 9: Get the count from stack pointer.
STEP10: Subtract the count from sum(content of DE pair).
STEP11:If the subtraction results a carry add the count to the result and get the remainder
STEP12: Otherwise increment B register content and go to STEP10.
STEP 13: Store the quotient and remainder in successive memory location.
PROGRAM:
MEMORY
LOATION
4100

MAHINE
CODE
21,00,42

4103

46

MOV B,M

4104

C5

PUSH B

4105
4106
4107
4108

AF
57
5F
23

XRA A
MOV D,A
MOV E,A
INX H

4109

86

ADD M

410A

D2,0E,41

JNC LOOP2

LABEL

LOOP1

MNEMONICS

COMMENTS

LXI H, 4200

Initialize HL register pair


with memory pointer
Transfer the memory
content to B register
Push the content of B
register to stack pointer
Clear accumulator
Clear D register
Clear E register
Increment memory
pointer
Add the content of
memory location to
accumulator
Jump on no carry to
LOOP2

410D

14

INR D

410E

05

410F

C2,08,41

JNZ LOOP1

4112

5F

MOV E,A

4113

C1

POP B

4114
4116

26,00
68

MVI H,00
MOV L,B

4117
4118

44
7B

MOV B,H
MOV A, E

4119

95

SUB L

411A

5F

MOV E,A

411B

7A

MOV A, D

411C

9C

SBB H

411D
4120

DA,25,41
57

JC LOOP3
MOV D,A

4121
4122
4125
4126

04
C3,18,41
7B
85

INR B
JMP LOOP 4
MOV A,E
ADD L

4217

5F

MOV E,A

4128

78

MOV A,B

4129

32,00,43

STA 4300

412C

EB

XCHG

412D

22,01,43

SHLD

4130

76

HLT

LOOP2

LOOP4

LOOP3

DCR B

4301

Increment D register
content
Decrement B register
content
Jump on no zero to
LOOP1
Move the content of
accumulator to E register
Retrieve the content of B
register from stack
Clear H register
Move the [B] to L
register
Clear B register
Mover the[E] content to
accumulator
Subtract [L] content from
accumulator
Move the accumulator
content to E register
Move the[D] to
accumulator
Subtract [H] from
accumulator through
borrow
Jump on carry to LOOP3
Move accumulator
content to D register
Increment B register
Jump to LOOP4
Move[E] to accumulator
Add [L] with
accumulator content
Move accumulator
content to E register
Move [B] register to
accumulator
Store the accumulator
content in 4300
Exchange [DE]
With [HL]
Store the remainder in
4301 and 4302
Ends execution

SAMPLE INPUT AND OUTPUT:


MEMORY
INPUT
LOCARION

MEMORY
LOCATION

OUTPUT

RESULT:
Thus an 8085 assembly language program that finds average of N numbers was
written and executed using microprocessor kit.

4 b) SQUARE ROOT OF A NUMBER


AIM:
To write an assembly language program to find the square root of a number
and execute the program using 8085 microprocessor kit.
APPARATUS REQUIRED:
8085 microprocessor kit, power supply.
METHOD TO FIND SQUARE ROOT OF A NUMBER:
Suppose that X is the square root of number N. To find the square root,
we derive the following equation
Let X2=N
Add X on both sides. Then
2 X2=N+ X2
X2=(N+ X2)/2
X=(N+ X2)/(2*X)
X=((N/X)+X)/2
Xnew= ((N/X)+X)/2
2

To find the square root of a given number we provide an initial guess X.


With this value we calculate Xnew and compare it with X. If Xnew=X, it gives the
result .If Xnew X then we take the Xnew as X and using the equation we find Xnew.
This process is repeated until Xnew=X.
ALGORITHM:
Step1: load HL register pair with a memory pointer.
Step2: get the number into accumulator and E register.
Step3: increment memory pointer.
Step4: get the initial guess to D and B registers.
Step5: call the division program.
Step6: add the initial guess with the accumulator.
Step7: divide the content of accumulator by 2 using division program.
Step8: if the calculated value is equal to guess, store the result in the memory location.
Step9: else take calculated value as guess and go to step5.
PROGRAM:
MEMORY
LOCATION
4100

MACHINE
CODE
21,00,42

LABEL

MNIMONICS

COMMENTS

LXIH, 4200

Initialize HL register
pair with memory

4103

7E

MOV A, M

4104

5E

MOV E, M

4105

23

INX

4106

56

MOV D, M

4107

46

MOV B,M

4108
410A
410D

0E,00
CD,1E,41
80

410E
4110
4112
4115

06,02
0E,00
CD,1E,41
7A

MVI B,02
MVI C,00
CALL DIV
MOV A,D

4116

51

MOV D,C

4117

B9

CMP C

4118

C2,28,41

JNZ LOOP1

411B

23

INX

411C

71

MOV M,C

411D
411E

76
90

HLT
SUB B

411F

DA,26,41

JC LOOP2

4122

0C

INR C

4123

C3,1E,41

JMP DIV

4126

79

4127

C9

LOOP3

DIV

LOOP2

MVI C,00
CALL DIV
ADDB

MOV A,C
RET

pointer
Transfer the content
of memory location to
accumulator
Transfer the content
of memory location to
E register
Increment memory
pointer
Move the initial guess
to D register
Move the initial guess
to to B register
Clear C register
Call division program
Add guess with
accumulator
Move 02 to B register
Clear C register
Call division program
Move [D] to
accumulator
Move [C] to D
register
Compare the guess
with calculated value
Jump on no zero to
loop1
Increment memory
pointer
Move [C] to memory
location
Ends execution
Subtract [B] from
accumulator
Jump on carry to
loop2
Increment C register
content
Jump to division
program
Move [C] to
accumulator
Return to main
program

4128

7B

LOOP1

MOV A,E

4129

41

MOV B,C

412A

C3,08,41

JMP LOOP3

Move[E] to
accumulator
Move [B] to C
register
Jump to loop3

SAMPLE INPUT AND OUTPUT:


INPUT DATA [4200]

OUTPUT DATA [4202]

RESULT:
Thus an 8085 assembly language program that finds the square root of a given
number was written and executed using microprocessor kit.

4 c)

GENERATION OF TIME DELAY

AIM:
To write an assembly language program to generate time delay and execute
the program using 8085 microprocessor kit.
APPARATUS REQUIRED:
8085 microprocessor kit, power supply.
ALGORITHM:
Step1:
Step 2:
Step 3:
Step 4:
Step 5:
Step 6:

Move the outer loop count to the C register.


Load the inner loop count to DE register pair.
Decrement DE reg pair content.
Check whether DE register pair content is 0, if not go to step 3.
Decrement C register.
If C register content is not 0, go to step 2.

CALCULATION:
DCX D 6T
MOV A,E4T
ORA D 4T
JNZ loop 10T
=24T
24N0.3310-6=0.5
N=63132
=(F69C)H
For delay of 10 s loop is called 20 times.
(20)10=14H
PROGRAM:
MEMORY
LOCATION
4100

MACHINE
CODE
0E,14

LABEL

MNEMONICS

COMMENTS

MVI C,14

Initialize outer
loop count
Initialize inner
loop count
Decrement
inner loop
count
Move the

4102

11,9C,F6

Loop 1

LXI

4105

1B

Loop

DCX

4106

7B

D,F69C
D

MOV A,E

4107

B2

ORA D

4108

C2,05,41

JNZ Loop

410B

0D

DCR C

410C

C2,02,41

JNZ Loop1

410F

C7

RST

contents of E
register to
accumulator
Check whether
DE register pair
contents is zero.
If [DE] not zero
go to loop
Decrement
outer loop
count
If [C]not zero
go to loop1
Reset

RESULT:
Thus the time delay of 10 seconds has been generated using microprocessor
8085 kit and the output has been verified.

4 d) DECIMAL COUNTER
AIM:
To write an assembly language program to realize a decimal counter and
execute the program using 8085 microprocessor kit.
APPARATUS REQUIRED:
8085 microprocessor kit, power supply.
ALGORITHM:
Step 1:initialize L register with 00.
Step 2:adjust the contents of Lregister to decimal value and store it in 4200.
Step 3:call monitor program to display L register in data field.
Step 4: call delay program to give a delay of two sec.
Step 5: copy the contents of 4200 to L register through A
Step 6:increment contents of Lregister and go to step 2.
SUBROUTINE:
Step1:move the outer loop count to the C register.
Step 2:load the inner loop count to DE register pair.
Step 3:decrement DE reg pair content.
Step 4:check whether DE register pair content is 0, if not go to step 3.
Step 5: decrement C register.
Step 6:if C register content is not 0, go to step 2.
CALCULATION:
DCX D 6T
MOV A,E4T
ORA D 4T
JNZ loop 10T
=24T
24N0.3310-6=0.5
N=63132
=(F69C)H
For delay of 2 s loop is called 4 times.
(4)10=(4)H
MEMORY
LOCATION
4300

MACHINE
CODE
2E,00

LABEL

MNEMONICS

COMMENTS

MVI L,00

Initialize L
register with 00

4302

7D

Loop 1

MOV A,L

4303

27

DAA

4304

6F

MOV L,A

4305

32,00,42

STA 4200

4308

3E,0B

MVI A,0B

430A

0E,02

MVI C,02

430C

CD,05,00

CALL 0005

430F

CD,00,41

CALL delay

4312

3A,00,42

LDA 4200

4315

6F

MOV

4316

2C

INR L

4317

C3,02,43

JMP Loop

Move the
contents of L
register to
accumulator.
Decimal adjust
accumulator
Move the
contents of L
register to
accumulator.
Store the
accumulator
contents to
4200
Initialize
accumulator
with 0B
Initialize C
register with 02
Call monitor
program to
display L
register
contents
Call delay
program
Load
accumulator
with 4200
contents
Move
accumulator to
L register
contents
Increment L
register
contents
Jump to loop

MNEMONICS

COMMENTS

MVI

Initialize outer

L,A

SUBROUTINE:
MEMORY
LOCATION
4100

MACHINE
CODE
0E,04

LABEL

C,04

4102

11,9C,F6

Loop 1

LXI D,F69C

4105

1B

Loop

DCX D

4106

7B

MOV A,E

4107

B2

ORA D

4108

C2,05,41

JNZ Loop

410B

0D

DCR C

410C

C2,02,41

JNZ Loop1

410F

C9

RET

loop count
Initialize inner
loop count
Decrement
inner loop
count
Move the
contents of E
register to
accumulator
Check whether
DE register pair
contents is zero.
If [DE] not zero
go to loop
Decrement
outer loop
count
If [C]not zero
go to loop1
Return to main
program

RESULT:
Thus the decimal counter has been realized using 8085 microprocessor kit and
the result has been verified.

4 e) HEXADECIMAL COUNTER
AIM:
To write an assembly language program to realize a hexadecimal counter and
execute the program using 8085 microprocessor kit.
APPARATUS REQUIRED:
8085 microprocessor kit, power supply.
ALGORITHM:
Step 1:
Step 2:
Step 3:
Step 4:
Step 5:
Step 6:

Initialize L register with 00.


Store the contents of Lregister in 4200.
Call monitor program to display L register in data field.
Call delay program to give a delay of two sec.
Copy the contents of 4200 to L register through A
Increment contents of Lregister and go to step 2.

SUBROUTINE:
Step1:
Step 2:
Step 3:
Step 4:
Step 5:
Step 6:

Move the outer loop count to the C register.


Load the inner loop count to DE register pair.
Decrement DE reg pair content.
Check whether DE register pair content is 0, if not go to step 3.
Decrement C register.
If C register content is not 0, go to step 2.

CALCULATION:
DCX D 6T
MOV A,E4T
ORA D 4T
JNZ loop 10T
=24T
24N0.3310-6=0.5
N=63132
=(F69C)H
For delay of 2 s loop is called 4 times.
(4)10=4H

MEMORY
LOCATION
4300

MACHINE
CODE
2E,00

LABEL

4302

7D

Loop 1

4303

32,00,42

STA 4200

4306

3E,0B

MVI A,0B

4308

0E,02

MVI C,02

430A

CD,05,00

CALL 0005

430D

CD,00,41

CALL delay

4310

3A,00,42

LDA 4200

4313

6F

MOV L,A

4314

2C

INR L

4315
C3,02,43
SUBROUTINE:
MEMORY
LOCATION
4100

MACHINE
CODE
0E,04

LABEL

4102

11,9C,F6

Loop 1

MNEMONICS

COMMENTS

MVI L,00

Initialize L
register with 00
Move the
contents of L
register to
accumulator.

MOV A,L

JMP Loop

Store the
accumulator
contents to
4200
Initialize
accumulator
with 0B
Initialize C
register with 02
Call monitor
program to
display L
register
contents
Call delay
program
Load
accumulator
with 4200
contents
Move
accumulator to
L register
contents
Increment L
register
contents
Jump to loop

MNEMONICS

COMMENTS

MVI C,04

Initialize outer
loop count
Initialize inner

LXI D,F69C

4105

1B

Loop

DCX D

4106

7B

MOV A,E

4107

B2

ORA D

4108

C2,05,41

JNZ Loop

410B

0D

DCR C

410C

C2,02,41

JNZ Loop1

410F

C9

RET

loop count
Decrement
inner loop
count
Move the
contents of E
register to
accumulator
Check whether
DE register pair
contents is zero.
If [DE] not zero
go to loop
Decrement
outer loop
count
If [C]not zero
go to loop1
Return to main
program

RESULT:
Thus the hexadecimal counter has been realized using 8085 microprocessor kit
and the result has been verified.

Questions and Answers


1. What is meant by looping and indexing? Explain.
2. Explain about following instructions.
i) LHLD ii) RAR iii) SPHL
3. What are the different addressing modes in 8085? explain with examples.
4. Differentiate between memory mapped I/O and peripheral I/O?
5. What is meant by polling? Explain.
6 . Explain in detail about interrupt structure of 8085?
7. Write about the following instructions.
i) PUSH
ii) XTHL
iii) PCHL
8 What is the function of HOLD pin in 8085?

9. Differentiate between 8088 and 8086?


10. What is meant by cycle stealing?

EXERCISE
1. Write an 8085 assembly language program to compute the HCF of two 16-bit
numbers stored in word locations X and X+2. Store the result in word location X+4.
2. Write an 8085 assembly language program to compute the LCM of two 16-bit
numbers stored in word locations X and X+2. Store the result in word location X+4
and X+6.
3. Write an 8085 assembly language program to compute the HCF of two 4-digit
BCD numbers stored in word locations X and X+2. Store the result in word location
X+4.
4. Write an 8085 assembly language program to compute the LCM of two 4-digit
BCD numbers stored in word locations X and X+2. Store the result in word location
X+4.
5. Write an 8085 assembly language program to convert a 32 bit binary number
stored in locations X to X+3 to equivalent BCD number. Store the result in locations
X+4 and X+7.
6. Write an 8085 assembly language program to convert a 8-digit BCD number
stored in locations X to X+3 to equivalent binary number. Store the result in
locations X+4 to X+7.
7. Write an 8085 assembly language program to sort a given set of 16-bit numbers in
ascending order using Bubble sort algorithm. The number of elements to be sorted
is provided in location X. The elements are in word locations starting from X+1.
8. Write an 8085 assembly language program to sort a given set of 16-bit numbers in
descending order using Selection sort algorithm. The number of elements to be
sorted is provided in location X. The elements are in word locations starting from
X+1.

You might also like