1
;Copyright (C) 2010 Kirantej J L <kirantej1920@gmail.com>
2
;Distributed under same license as rest of the program i.e. GPL v2 or later.
3
;See COPYING file for license text.
7
; This program is the famous bubble sorting technique, it compares sucessive elements and then sorts
8
; This assumes that data is stored in memory location 50
9
; Change the initial value of C-register in line-no 17 for different number of inputs
10
; The sorted elements are stored in memory location -50
18
start: LXI H,50 ;set up as a momory pointer for the bytes
19
MVI D,00 ;Clear register D to set up a flag
20
MVI C,04 ;Set register C for comparision count
21
Check: MOV A,M ;Get data byte
22
INX H ; point to next byte
24
JC NXTBYT ;if (A) < second byte, do not exchange
25
MOV B,M ;Get second byte for exchange
26
MOV M,A ;Store first byte in second location
27
DCX H ;Point to first location
28
MOV M,B ;Store second byte in first location
29
INX H ;Get ready for second comparision
30
MVI D,01 ;Load 1 in D as a remainder for exchange
31
NXTBYT: DCR C ;Decrement comparision count
32
JNZ Check ;If comparision count != 0, go back
33
MOV A,D ;Get flag bit in A
34
RRC ; place flag bit D0 in carry
35
JC start ;If flag is 1. exchange occured