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

Discussion in 'Assembly Language Programming (ALP) Forum' started by felixChew, Nov 13, 2009.

  1. felixChew

    felixChew New Member

    Joined:
    Nov 5, 2009
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Code:
    ; 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 =)
     
  2. plchidamparam

    plchidamparam New Member

    Joined:
    Jan 24, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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!!!
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice