Subject: Re: Aw: Re: Aw: Re: [stella] Sorting Algorithms. From: Julian Squires <tek@xxxxxxx> Date: Tue, 26 Mar 2002 12:52:59 -0330 |
Good day. On Mon, Mar 25, 2002 at 03:18:01PM +0100, cybergoth@xxxxxxxx wrote: > ...I'd like to ask you, if you probably could type in both the bubble and > the insertion sort for me? No problem. I was going to offer to post them in 6502 assembler, but it shouldn't be very hard to translate. Program S (Straight insertion sort). The records to be sorted are in locations INPUT+1 through INPUT+N; they are sorted in place in the same area, on a full-word key. rI1 == j - N; rI2 == i; rA == R == K; assume that N >= 2. 01 START ENT1 2-N 1 S1. Loop on j. j <- 2. 02 2H LDA INPUT+N,1 N-1 S2. Set up i, K, R. 03 ENT2 N-1,1 N-1 i <- j - 1. 04 3H CMPA INPUT,2 B+N-1-A S3. Compare K : K_i. 05 JGE 5F B+N-1-A To S5 if K >= K_i. 06 4H LDX INPUT,2 B S4. Move R_i, decrease i. 07 STX INPUT+1,2 B R_{i+1} <- R_i. 08 DEC2 1 B i <- i - 1. 09 J2P 3B B To S3 if i > 0. 10 5H STA INPUT+1,2 N-1 S5. R into R_{i+1}. 11 INC1 1 N-1 12 J1NP 2B N-1 2 <= j <= N. [] Program B (Bubble sort). rI1 == t; rI2 == j. 01 START ENT1 N 1 B1. Initialize BOUND. t <- N. 02 1H ST1 BOUND(1:2) A BOUND <- t. 03 ENT2 1 A B2. Loop on j. j <- 1. 04 ENT1 0 A t <- 0. 05 JMP BOUND A Exit if j >= BOUND. 06 3H LDA INPUT,2 C B3. Cmp/exchange R_j:R_{j+1}. 07 CMPA INPUT+1,2 C 08 JLE 2F C No exchange if K_j <= K_{j+1}. 09 LDX INPUT+1,2 B R_{j+1} 10 STX INPUT,2 B -> R_j. 11 STA INPUT+1,2 B (old R_j) -> R_{j+1}. 12 ENT1 0,2 B t <- j. 13 2H INC2 1 C j <- j + 1. 14 BOUND ENTX -*,2 A+C rX <- j - BOUND. [modified] 15 JXN 3B A+C Do step B3 for 1 <= j < BOUND. 16 4H J1P 1B A B4. Any exchanges? To B2 if t > 0. [] I can type in the pseudocode for these as well, if you are interested. -- -/ |/| Julian Squires <tek@xxxxxxx> /- ---------------------------------------------------------------------------------------------- Archives (includes files) at http://www.biglist.com/lists/stella/archives/ Unsub & more at http://www.biglist.com/lists/stella/
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Aw: Re: Aw: Re: [stella] Sorting Al, Thomas Jentzsch | Thread | Aw: Re: Aw: Re: Aw: Re: [stella] So, cybergoth |
Re: [stella] Bubble Sort, Andrew Davie | Date | Re: [stella] Bubble Sort, Thomas Jentzsch |
Month |