; sorting ascending number from the memory
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 =)