Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Assembly Language Programming (ALP) Forum (http://www.go4expert.com/forums/assembly-language-programming-forum/)
-   -   ALP for 8085 processor to perform sorting to arrange the numbers in ascending order. (http://www.go4expert.com/forums/alp-8085-processor-perform-sorting-t20086/)

felixChew 14Nov2009 02:12

ALP for 8085 processor to perform sorting to arrange the numbers in ascending order.
 
Code: ALP

; sorting ascending number from the memory
LXI H,3000;
MVI M,80;
INX H;
MVI M,75;
INX H;
MVI M,45;
INX H;
MVI M,85;
INX H;
MVI M,35;
INX H;
MVI M,55;
INX H;
MVI M,74;
INX H;
MVI M,27;
INX H;
MVI M,90;
INX H;
MVI M,52;
MVI C,9;

REPEAT:
MOV D,C
LXI H,3000

LOOP:
MOV A,M
INX H
CMP M
JC SKIP
MOV B,M
MOV M,A
DCX H
MOV M,B
INX H

SKIP:
DCR D
JNZ LOOP
DCR C
JNZ REPEAT
HLT



This set of program code includes registers as counter and loops. Firstly, load register pair HL with 3000 immediate data to locate the memory address location and move immediate data into the memory.

Next, increment register pair HL data by one to load the next memory location and store the next data of the data array.

After moving the data array into the memory, move 9h immediate data into register C as the counter of the total number of the data array.

REPEAT loop is created to move register C data to register D and load the register pair HL with 3000 immediate data to locate the memory address.

Next, another loop is created which is called the LOOP to sort the data from the smallest to the largest.

The loop function consists of moving memory data to register A, increment register pair HL data by one and compare register A data with memory data.

It will jump to SKIP loop if the carry flag is equal 1 by using the code JNC.

If the carry flag is equal to 1, it will continue the next line which is to move memory data to register B as a temperary location for the data to stored in.

Next, move register A data into memory address and dercement register pair HL data by one. Then, move register B data into memory address and increment register HL pair by one again. The SKIP loop decrement register D data and jump to LOOP loop if register D data is not equal to 0. Next, decrement register C and jump to REPEAT loop if register C data is not equal to 0. HLT code is used to stop the program.

For descending order....change JC SKIP to JNC SKIP

Sorry for my poor language =(
reply if u think this helps u =)

plchidamparam 24Jan2010 22:26

Re: ALP for 8085 processor to perform sorting to arrange the numbers in ascending ord
 
Thanks for you program but i need the algorithm please mail me to plchidamparam@yahoo.co.in i cant understand what you have did exactly so only please!!!


All times are GMT +5.5. The time now is 00:51.