[stella] Bubble Sort (Rodnay Zaks Version)

Subject: [stella] Bubble Sort (Rodnay Zaks Version)
From: "Ronald A. Laski, Jr." <rlaski@xxxxxxxxxxx>
Date: Tue, 26 Mar 2002 04:00:20 -0600
This is the Rodnay Zaks Bubble Sort (if anybody cares! :)

Ron
TAB		.WORD $600
		* = $200
SORT		LDX #0		;Set 'Exchanged' to 0 (in other words, SwapFlag = FALSE) - Ron
		LDA (TAB,X)	
		TAY		; Number of elements is in Y
LOOP		LDA (TAB),Y	; Read Element E(I)
		DEY		; Decrement number of elements to read.
		BEQ FINISH	; End if no more elements
		CMP (TAB), Y	; Compare to E'(I)
		BCS LOOP	; Get next element IF E(I) > E'(I)
EXCH		TAX		; Exchange elements
		LDA (TAB), Y
		INY
		STA (TAB), Y
		TXA
		DEY
		STA (TAB), Y
		LDX #1		; Set 'Exchanged' to 1 (in other words, SwapFlag = TRUE) - Ron
		BNE LOOP	; Get next element
FINISH	TXA		; Shift 'Exchanged' to a reg. for compare...
		BNE SORT	; If some exchanges are made, do another pass.
		RTS
		.end

Anyway, hope it helps... i'm not saying it's optimized or anything, but here it is...


---------------------------------------------------------------------------------------------- Archives (includes files) at http://www.biglist.com/lists/stella/archives/ Unsub & more at http://www.biglist.com/lists/stella/


Current Thread