Program For Arranging Data Array in Ascending Order

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Lab-4-MPES

Aim
1. Program for arranging data array in ascending order
2. Program for arranging data array in descending order

Apparatus
 Microprocessor Kit 8085 , Key Board, Op-Code Sheet.
Theory
     
Program for arranging data array in ascending order:
In the programmer three counts have been used. Count 1 is stored in register B to check whether all the numbers of the
series have been arranged in ascending order. Count 2 is stored in register C tocheck whether all the numbers of the series
have been compared while selecting the smallest number of the series. After the selection of the smallest number it is to be
ascertained which number was the smallest. At this stage register C is free . The register C is again used in SUBROUTINE-
2 to store count 3 to check which number has been selected as the smallest number. The smallest number is replaced by FF
in the series. Again the program to find smallest number is taken up to select  the smallest number in the modified series.

Program for arranging data array in descending order :


In the programmer three counts have been used. Count 1 is stored in register B to check whether all the numbers of the
series have been arranged in descending order. Count 2 is stored in register C to check whether all the numbers of the series
have been compared while selecting the highest number of the series. After the selection of the highest number it is to be
ascertained which number was the smallest. At this stage register C is free. The register C is again used in SUBROUTINE-2
to store count 3 to check which number has been selected as the largest number. The largest number is replaced by 00 in the
series. Again the program to find largest number is taken up to select the largest number in the modified series.

Precautions
1. All steps should be followed carefully.

2. Make sure all power sources are disconnected

3. Make sure you are properly grounded.

4. Don’t touch the live wire.

Procedure
Program for arranging data array in ascending order:
1.  Key in the Opcodes from the address specified.

2.  Enter data from 4500, specified in the example.

3.  Execute the program and check for the result from 4601.

4.  Change data from 4500 and execute each time and check for result.

Program for arranging data array in descending order:


1.  Key in the Opcodes from the address specified.

2.  Enter data from 4500, specified in the example.

3.  Execute the program and check for the result from 4601.
4.  Change data from 4500 and execute each time and check for result.

Program Code and object code


 
Program for arranging data array in ascending order:
Memory Address Opcodes Mnemonics Comments
4100 11, 01, 46 LXI D, 4601 Memory location to store result
4103 21, 00, 45 LXI  H,4500 Count address in H-L pair.
4106 46 MOV  B,M Count in register B to check
whether all number have been
arranged in ascending order.
4107 CD, 00, 44 START:    CALL  4400 Call Subroutine-! To find
smallest number.
410A 12 STAX  D Store the result
410B CD, 50, 42                 CALL  4250 Call Subroutine-2 to check which
number is smallest.
410E 13 INX D  
410F 05   DCR  B Have all numbers been arranged
in ascending order?
4110 C2, 07, 41                     No, repeat process.
JNZ      :START
4113 76                    HLT Stop

SUBROUTINE-1: To Find the Smallest Number


Memory Address Opcodes Mnemonics Comments
4400 21, 00, 45 LXI H, 4500 Count address in H-L pair.
4403 4E MOV C,M Count in register C.
4404 3E,FF MVI A,FF Get FF in accumulator.
4406 23 LOOP:  INX H  
4407 BE CMP M Compare next number with
previous smallest. Is next
number< previous smallest ?
4408 CD, 0C,44                     No,smallest number is in the
JC        :AHEAD accumulator. Go to AHEAD.
440B 7E MOV A,M  
440C 0D AHEAD:     DCR C  
441D C2, 06, 44                     JNZ      :LOOP  
4410 C9                    RET  
 
SUBROUTINE-2 :
Memory Address Opcodes Mnemonics Comments
4250 21, 00, 45 LXI H, 4500  
4253 4E MOV C,M Count to check which number
was smallest.
4254 23 BEHIND:   INX H Get next number.
4255 BE                 CMP M Compare the next number with
smallest number which is in the
accumulator.
4256 CA, X,X                 JZ      Is the present number the smallest
:FORWARD one? Yes, go to FORWARD.
4259 0D DCR C Decrement count.
425A C2,X,X   No, jump to take up next number.
JNZ      :BEHIND
425D 3E, FF FORWARD:   MVI A, FF  
425F 77 MOV M, A Replace the smallest number by
FF.
4260 C9 RET  
 
 

Program for arranging data array in descending order:


Memory Address Opcodes Mnemonics Comments
4100 21, 00, 45     LXI H, 4500 Address for count.
4103 4E  MOV C,M Count for number of passes in
register C.
4104 21, 00, 45 BACK:    LXI H,4500  
4107 56                MOV D,M Count for number of Comparison
in register D.
4108 23                INX  H  
4109 7E                 MOV A,M 1st number in accumulator.
410A 23 LOOP:    INX H Address of next number.
410B 46    MOV B, M Next number in register B.
410C B8                CMP B Compare next number with
previous greatest number.
410D D2, 16, 41               JNC      :AHEAD If previous greater number > next
number, go to AHEAD.
4110 2B               DCX H  
4111 77               MOV M,A Place smaller of the two
compared numbers in memory
4112 78              MOV A,B Place greater of the two numbers
in accumulator.
4113 C3, 18, 41              JMP                 :GO  
4116 2B AHEAD:    DCX H  
4117 70        MOV  M,B Place smaller of the two
compared numbers in memory.
4118 23 GO:           INX H  
4119 15 DCR D Decrease the count for
comparisons.
411A C2, 0A, 41                   JNZ       :LOOP  
411D 77       MOV M, A Place the greatest number after a
pass in the memory.
411E 0D DCR C Decreased the count for passes
411F C2, 04, 41                   JNZ    
:BACK
4122 76                   HLT Stop
 
Results

Program for arranging data array in ascending order:


1):   DATA                                                            RESULT

      4500- 05                                                        4601-15                        

      4501-E5                                                         4602-96

      4502-A9                                                         4603-A9

      4503-96                                                         4604-B4

      4504-B4                                                        4605-E5

      4505-15                                                                  

2):  DATA                                                            RESULT

      4500- 06                                                       4601-30                        

      4501-45                                                        4602-45

      4502-B8                                                        4603-98

      4503-FF                                                        4604-B8

      4504-E8                                                       4605-E8

      4505-98                                                       4606-FF            

      4506-30

 Program for arranging data array in descending order:


DATA                                                            RESULT

4500- 04 (COUNT)                                     4601-15                        

4501-60                                                       4602-25

4502-40                                                       4603-40

4503-50                                                       4604-50
 4504-15                                                      4605-60

 4505-25       

                                                           

 Sources of Error

1. Select op-codes carefully whenever you doing programming.


2. Make space whenever you doing program on kit.
3. You should properly enter the program and exit through proper command

You might also like