Exp No 2A

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

Exp No: 2(A) PROGRAMS WITH CONTROL INSTRUCTIONS

Aim:
To write an assembly language program with the help of 8085Microprocessor control
instructions to sort an array and to find maximum and minimum number in the given array.

Equipments Required:

Sl. No Item Specification Quantity


1. Microprocessor kit 8085 1
2. Power cord - 1

(a)-Ascending Order
Algorithm:

1. Get the numbers to be sorted from the memory locations.


2. Initialize row and column counters.
2. Compare the first two numbers and if the first number is larger than second then
interchange the number.
3. Decrement row counter and repeat the step 2 for remaining data, until the counter becomes zero.
4. Decrement column counter and repeat the steps 2 and 3.
Flowchart:
START

[B]  04H

[HL]  [8100H]

[C]  04H

[A]  [HL]

[HL  [HL] + 1

YES IS
[A] < [HL]?

NO
[D] [HL]

[HL]  [A]

[HL]  [HL] - 1

[HL]  [D]

[HL]  [HL] + 1

[C]  [C] – 01 H

IS
[C] = 0? NO

YES
[B]  [B]-1

IS NO
[B] = 0?

YES
STOP
Program:

ADDRESS OPCODE LABEL MNEMONICS OPERAND COMMENTS


4100 06 MVI B,04 Initialize B reg with number
4101 04 of comparisons (n-1)
4102 21 LOOP 3 LXI H,4500 Initialize HL reg. to
4103 00 4100H
4104 45
4105 0E MVI C,04 Initialize C reg with no. of
4106 04 comparisons(n-1)
4107 7E LOOP2 MOV A,M Transfer first data to acc.
4108 23 INX H Increment HL reg. to point
next memory location
4109 BE CMP M Compare M & A
410A DA JC LOOP1 If A is less than M then go to
410B 12 loop1
410C 41
410D 56 MOV D,M Transfer data from M to D reg
410E 77 MOV M,A Transfer data from acc to M
410F 2B DCX H Decrement HL pair
4110 72 MOV M,D Transfer data from D to M
4111 23 INX H Increment HL pair
4112 0D LOOP1 DCR C Decrement C reg
4113 C2 JNZ LOOP2 If C is not zero go to loop2
4114 07
4115 41
4116 05 DCR B Decrement B reg
4117 C2 JNZ LOOP3 If B is not Zero go to loop3
4118 02
4119 41
411A 76 HLT Stop the program

Observation:

INPUT OUTPUT
MEMORY MEMORY
DATA DATA
LOCATION LOCATION
4500 4500
4501 4501
4502 4502
4503 4503
4504 4504
Flowchart:
START

[B]  04H

[HL]  [4100H]

[C]  04H

[A]  [HL]

[HL  [HL] + 1

NO IS
[A] < [HL]?

YES
[D] [HL]

[HL]  [A]

[HL]  [HL] - 1

[HL]  [D]

[HL]  [HL] + 1

[C]  [C] – 01 H

B C
(b)-Descending Order

Algorithm:

1. Get the numbers to be sorted from the memory locations.


2. Initialize row and column counters.
2. Compare the first two numbers and if the first number is smaller than second then
interchange the number.
3. Decrement row counter and repeat the step 2 for remaining data, until the counter becomes zero.
4. Decrement column counter and repeat the steps 2 and 3.
B C

IS NO
[C] = 0?

YES
[B]  [B]-1

IS NO
[B] = 0?

YES

STOP
Program:

ADDRESS OPCODE LABEL MNEMONICS OPERAND COMMENTS


4100 06 MVI B,04 Initialize B reg with number
4101 04 of comparisons (n-1)
4102 21 LOOP 3 LXI H,4500 Initialize HL reg. to
4103 00 4100H
4104 45
4105 0E MVI C,04 Initialize C reg with no. of
4106 04 comparisons(n-1)
4107 7E LOOP2 MOV A,M Transfer first data to acc.
4108 23 INX H Increment HL reg. to point
next memory location
4109 BE CMP M Compare M & A
410A D2 JNC LOOP1 If A is greater than M then go
410B 12 to LOOP1
410C 41
410D 56 MOV D,M Transfer data from M to D reg
410E 77 MOV M,A Transfer data from acc to M
410F 2B DCX H Decrement HL pair
4110 72 MOV M,D Transfer data from D to M
4111 23 INX H Increment HL pair
4112 0D LOOP1 DCR C Decrement C reg
4113 C2 JNZ LOOP2 If C is not zero go to LOOP2
4114 07
4115 41
4116 05 DCR B Decrement B reg
4117 C2 JNZ LOOP3 If B is not Zero go to LOOP3
4118 02
4119 41
411A 76 HLT Stop the program

Observation:

INPUT OUTPUT
MEMORY LOCATION DATA MEMORY LOCATION DATA
4500 4500
4501 4501
4502 4502
4503 4503
4504 4504
Flow chart:
START

[HL]  [4100H]

[B]  04H

[A]  [HL]

[HL  [HL] + 1

NO IS
[A] < [HL]?

YES

[A] [HL]

[B]  [B]-1

IS NO
[B] = 0?

YES

[4105]  [A]

STOP
(c)-Maximum Number In An Array
Algorithm:
1. Place all the elements of an array in the consecutive memory locations.
2. Fetch the first element from the memory location and load it in the accumulator.
3. Initialize a counter (register) with the total number of elements in an array.
4. Decrement the counter by 1.
5. Increment the memory pointer to point to the next element.
6. Compare the accumulator content with the memory content (next element).
7. If the accumulator content is smaller, then move the memory content. (Largest element) to the
accumulator. Else continue.
8. Decrement the counter by 1.
9. Repeat steps 5 to 8 until the counter reaches zero
10. Store the result (accumulator content) in the specified memory location.
Program:

ADDRESS OPCODE LABEL MNEMONICS OPERAND COMMENTS


4100 21 LXI H,4500 Initialize HL reg. to
4101 00 4100H
4102 45
4103 06 MVI B,04 Initialize B reg with no. of
4104 04 comparisons(n-1)
4105 7E MOV A,M Transfer first data to acc.
4106 23 LOOP1 INX H Increment HL reg. to point
next memory location
4107 BE CMP M Compare M & A
4108 D2 JNC LOOP If A is greater than M then go
4109 0C to LOOP
410A 41
410B 7E MOV A,M Transfer data from M to A reg
410C 05 LOOP DCR B Decrement B reg
410D C2 JNZ LOOP1 If B is not Zero go to LOOP1
410E 06
410F 41
4110 32 STA 4505 Store the result in a memory
4111 05 location.
4112 45
4113 76 HLT Stop the program
Flow chart:
START

[HL]  [4100H]

[B]  04H

[A]  [HL]

[HL  [HL] + 1

YES IS
[A] < [HL]?

NO

[A] [HL]

[B]  [B]-1

IS NO
[B] = 0?

YES

[4105]  [A]

STOP
Observation:

INPUT OUTPUT
ADDRESS DATA ADDRESS DATA
4500 4505
4501
4502
4503
4504

(d)-Minimum Number In An Array

Algorithm:
1. Place all the elements of an array in the consecutive memory locations.
2. Fetch the first element from the memory location and load it in the accumulator.
3. Initialize a counter (register) with the total number of elements in an array.
4. Decrement the counter by 1.
5. Increment the memory pointer to point to the next element.
6. Compare the accumulator content with the memory content (next element).
7. If the accumulator content is smaller, then move the memory content (largest element) to the
accumulator. Else continue.
8. Decrement the counter by 1.
9. Repeat steps 5 to 8 until the counter reaches zero
10. Store the result (accumulator content) in the specified memory location.

Program:

ADDRESS OPCODE LABEL MNEMONICS OPERAND COMMENTS


4100 21 LXI H,4500 Initialize HL reg. to
4101 00 4100H
4102 45
4103 06 MVI B,04 Initialize B reg with no. of
4104 04 comparisons(n-1)
4105 7E MOV A,M Transfer first data to acc.
4106 23 LOOP1 INX H Increment HL reg. to point
next memory location

22
23
4107 BD CMP M Compare M & A
4108 DA JC LOOP If A is lesser than M then go
4109 0C to LOOP
410A 41
410B 7E MOV A,M Transfer data from M to A reg
410C 05 LOOP DCR B Decrement B reg
410D C2 JNZ LOOP1 If B is not Zero go to LOOP1
410E 06
410F 41
4110 32 STA 4505 Store the result in a memory
4111 05 location.
4112 45
4113 76 HLT Stop the program

Observation:

INPUT OUTPUT
ADDRESS DATA ADDRESS DATA
4500 4505
4501
4502
4503
4504

Result:
Thus the programs for sorting of an array and to find maximum and minimum value in the given
array by using 8085 microprocessor are written, executed and their outputs are observed.
25

You might also like