Вы находитесь на странице: 1из 9

3.

a) SMALLEST OR LARGEST NUMBER IN AN ARRAY


Aim:
To write an 8085 assembly language program that finds the smallest (or largest
number in an array and execute the program using microprocessor kit.
Apparatus required: 8085 Microprocessor kit, Power supply
Algorithm:
Smallest number in an array
Step 1:
Step 2:
Step 3:
Step 4:
Step 5:
Step 6:

Memory
Location

Initialize HL register pair with a memory pointer.


Get the count to B register and decrement the count.
Increment the memory pointer
Move contents of memory pointer to accumulator.
Increment memory pointer and compare the contents with accumulator.
If carry results decrement count else move contents of memory pointer to
accumulator.
If count becomes zero increment the memory pointer and store contents of
accumulator to that memory location.
Machine
Label Mnemonics Comment
code

4100

21,00,42

LXI H, 4200 Initialize HL register pair with a


memory pointer

4103

46

MOV B, M Transfer the count to B register

4104

05

DCR B

Decrement B register

4105

23

INX H

Increment memory pointer

4106

7E

MOV A, M

Get first number to accumulator

4107

23

INX H

Increment memory pointer

4108

BE

CMP M

Compare the contents of memory


location with accumulator

4109

DA, 0D, 41

JC

410C

7E

MOV A, M

410D

05

410E

C2, 07, 41

JNZ LOOP2 If [B]=0 go to LOOP 2

4111

23

INX H

4112

77

MOV M, A Move the smallest number to memory


location

4113

76

HLT

Step 7:

LOOP1 If [A]<[M] go to LOOP1

LOOP1 DCR B

Move [M] to accumulator


Decrement the count
Increment memory pointer

End execution

Sample input and output:


Dataset 1
Memory location

Data

Memory location

Data

Dataset 2

Largest number in an array


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

Initialize HL register pair with a memory pointer.


Get the count to B register and decrement the count.
Increment the memory pointer
Move contents of memory pointer to accumulator.
Increment memory pointer and compare contents with accumulator.
If no carry results decrement count else move contents of memory pointer
to accumulator.
If count becomes zero increment the memory pointer and store contents of
accumulator to that memory location.

Sample input and output


Memory Location

Data

Memory
Location

Machine code Label Mnemonics

4100

21,00,42

LXI H, 4200 Initialize HL register pair with a


memory pointer

4103

46

MOV B, M Transfer the count to B register

4104

05

DCR B

Decrement B register

4105

23

INX H

Increment memory pointer

4106

7E

MOV A, M

Get first number to accumulator

4107

23

INX H

Increment memory pointer

4108

BE

CMP M

Compare the contents of memory


location with accumulator

4109

DA, 0D, 41

JNC LOOP1 If [A]>[M] go to LOOP1

410C

7E

MOV A, M

410D

05

410E

C2, 07, 41

JNZ
LOOP2

If [B]=0 go to LOOP 2

4111

23

INX H

Increment memory pointer

4112

77

MOV M, A Move the smallest number to memory


location

4113

76

HLT

LOOP1 DCR B

Comment

Move [M] to accumulator


Decrement the count

End execution

Result: Thus an 8085 assembly language program that finds the smallest (or largest
number in an array was written and executed using microprocessor kit.

b) SORTING OF NUMBERS IN AN ARRAY


AIM:
To write an 8085 assembly language program that sorts the given array in
ascending order (or descending order) and execute the program using microprocessor kit.
Apparatus required: 8085 Microprocessor kit, Power supply

Algorithm

Ascending order
Step 1:
Step 2:
Step 3:
Step 4:
Step 5:
Step 6:
Step 7:
Step 8:
Step 9:

Initialize HL register pair as memory pointer.


Get the count and decrement it.
Increment memory pointer
Push the memory location and the count to stack pointer.
Call subroutine.
Get the count and memory location from stack pointer.
Move the contents of accumulator to memory location
Decrement the count, if it is not zero go to step 3.
Else end the execution

subroutine:
Step 1:
Step 2:
Step 3:
Step 4:
Step 5:

Move the contents of memory location to accumulator.


Increment memory pointer and compare it with the contents of
accumulator.
If carry does not exist swap the contents of accumulator and memory
pointer.
Decrement the count, if count is not zero go to step 2.
Else return to main program.

Sample input and output


Memory Location

Data

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

Initialize HL register pair as memory pointer.


Get the count and decrement it.
Increment memory pointer
Push the memory location and the count to stack pointer.
Call subroutine.
Get the count and memory location from stack pointer.
Move the contents of accumulator to memory location
Decrement the count, if it is not zero go to step 3.

Step 9:

Else end the execution

subroutine:
Step 1:
Step 2:
Step 3:
Step 4:
Step 5:

Move the contents of memory location to accumulator.


Increment memory pointer and compare it with the contents of
accumulator.
If carry exists swap the contents of accumulator and memory pointer.
Decrement the count, if count is not zero go to step 2.
Else return to main program.

Memory
Location

Machine
code

Label Mnemonics

Comment

4100

21,00,42

LXI H, 4200

Initialize HL register pair with a


memory pointer

4103

46

MOV B, M

Transfer the count to B register

4104

05

DCR B

Decrement B register

4105

23

LOOP1 INX H

4106

E5

PUSH H

Push the contents of HL register pair


to stack pointer

4107

C5

PUSH B

Push the contents of B register to


stack pointer

4108

CD, 13, 41

CALL

Call subroutine to find the smallest


number

410B

C1

POP B

Retrieve the contents of B from


stack

410C

E1

POP

Retrieve the contents of HL register


pair from stack

410D

77

MOV M, A

Move the smallest number to


memory location

410E

05

DCR B

Decrement register B

411F

C2, 05, 41

JNZ LOOP 1

If [B]=0 go to LOOP 2

4112

76

HLT

End execution

Increment memory pointer

Sub

SUBROUTINE
Memory
Location

Machine code Label

Mnemonics Comment

4113

7E

MOV A, M Transfer the contents of memory location


to accumulator

4114

23

LOOP 2 INX H

4115

BE

CMP M

4116

DA, 1C, 41

JC

4119

56

MOV D, M Move [M] to D register

411A

77

MOV M, A Move the contents of accumulator to


memory location

411B

7A

MOV A, D Move the [D] to accumulator

411C

05

DCR

411D

C2, 14, 41

JNZ
LOOP2

If [B]=0 go to LOOP 2

4120

C9

RET

Return to main program

Increment memory pointer


Compare the contents of memory
location with accumulator

LOOP1 If [A]<[M] go to LOOP1

Decrement counnt

Sample input and output


Memory Location

Data

Result:
Thus an 8085 assembly language program that sorts the given array in ascending
order (or descending order) was written and executed using microprocessor kit.

c). BLOCK TRANSFER

Aim:
To Write an assembly language that transfer a block of data from one set of
memory locations to other set of locations and test 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:
Step 7:
Step 8:

Initialize the count value.


Initialize the source memory pointer.
Initialize the destination memory pointer.
Move the contents of source memory to accumulator.
Store the accumulator to destination memory location.
Increment the source and the destination memory pointers.
Decrement the count, if count is not zero, go to step 4.
Else stop.

Memory
Location

Machine
code

Label Mnemonics Comment

4100

06 , 05

MVI B, 05

4102

21, 00, 42

LXI H, 4200 Initialize HL register pair as source


memory pointer

Initialize a count

4105

11, 00, 43

LXI D, 4200
Initialize DE register pair as Destination
memory pointer

4108

7E

LOOP MOV A, M Move the contents from source location


to accumulator

4109

12

STAX D

Store the contents of accumulator to


destination location

410A

23

INX H

Increment memory pointer

410B

13

INX D

Increment DE register pair

410C

05

DCR

410D

C2, 08, 41

JNZ LOOP Increment memory pointer

4110

76

HLT

Input
Source location

Decrement the count


End execution

Output
Data

Destination location

4200

4300

4201

4301

4203

4302

4204

4303

4205

4304

Data

Result:
Thus an assembly language that transfer a block of data from one set of memory
locations to other set of locations was written and tested using 8085 microprocessor kit.
Questions and Answers:
1.
Define: Instruction cycle, Machine cycle, T-state
2.
What are 8085 interrupts ? Discuss in detail.
3.
Explain the functions of the ALE and IO/M signals of the 8085
microprocessor
4.
With suitable examples explain in detail about the following instructions
a. STAX D
b. LDAX B
c. SPHL
d. PUSH B
EXERCISE

1. A block of data is stored in the memory locations from XX55H to XX5AH.


Transfer the data to locations XX80H to XX85 H in the reverse order
2. Data bytes are stored in memory locations from XX50 H to XX5FH. To insert
an additional five data bytes, it is necessary to shift the data string by five
memory locations. Write a program to store the data string from XX55H to
XX64H.