Add example of K1 and K2 declarations to sort3
This commit is contained in:
parent
aa13da3219
commit
772472d932
53
sort3.uc
53
sort3.uc
@ -1,10 +1,16 @@
|
|||||||
|
#optable 0xf @BREAK
|
||||||
|
#amode 3 @BREAK
|
||||||
|
|
||||||
|
|
||||||
#define LIST_START 0xE0
|
#define LIST_START 0xE0
|
||||||
#define HASH_MASK 0b1111
|
#define HASH_MASK 0b1111
|
||||||
#define FIRST_BUCKET 0x10 // Index of start of first bucket
|
#define FIRST_BUCKET 0x10 // Index of start of first bucket
|
||||||
#define LAST_BUCKET 0xD3 // Index of start of last bucket
|
#define LAST_BUCKET 0xD3 // Index of start of last bucket
|
||||||
#define BUCKET_SIZE 13 // Each bucket an hold 13 elements before spilling
|
#define BUCKET_SIZE 13 // Each bucket an hold 13 elements before spilling
|
||||||
|
|
||||||
|
// LUT entries contain pointers to last element in bucket
|
||||||
|
// This allows the LUT to serve as both a jump-table and as bucket-headers
|
||||||
|
// Look at me being all resourceful and stuff, huh? Inb4 slowdowns ;))
|
||||||
#data 0x00 0x77
|
#data 0x00 0x77
|
||||||
#data 0x01 0x84
|
#data 0x01 0x84
|
||||||
#data 0x02 0x91
|
#data 0x02 0x91
|
||||||
@ -24,17 +30,20 @@
|
|||||||
|
|
||||||
const LIST_START
|
const LIST_START
|
||||||
mov ar pc
|
mov ar pc
|
||||||
reset ir // Point PC to start of list. Let MUX activate GR3
|
|
||||||
|
|
||||||
// Two values sorted per iteration, so half the iterations obv ;)
|
// Two values sorted per iteration, so half the iterations obv ;)
|
||||||
lcset 16
|
// For consistency, we just decrement LC twice per iteration, though
|
||||||
|
// Had this course also stressed power use or other efficiency-related questions,
|
||||||
|
// we probably wouldn't decrement twice per iteration for the sole purpose of "clarity"
|
||||||
|
// But alas, Kent doesn't care, so why should we?
|
||||||
|
lcset 32
|
||||||
|
|
||||||
$BUCKET_SORT
|
$BUCKET_SORT
|
||||||
declc; bls @MERGE_INIT
|
bls @MERGE_INIT
|
||||||
|
|
||||||
mov pc asr; incpc
|
mov pc asr; incpc
|
||||||
mov pm ar; mov pm ir // Use whatever value we're sorting to index GR at complete random :)))))))
|
mov pm ar; mov pm ir // Use whatever value we're sorting to index GR at complete random
|
||||||
mov pc asr; incpc; incpc
|
mov pc asr; incpc
|
||||||
mov pm hr
|
mov pm hr
|
||||||
|
|
||||||
// Shift AR and HR
|
// Shift AR and HR
|
||||||
@ -48,7 +57,7 @@ mov pm ar
|
|||||||
add 1
|
add 1
|
||||||
mov ar pm
|
mov ar pm
|
||||||
mov ar asr
|
mov ar asr
|
||||||
mov gr pm
|
mov gr pm; declc // Mark element as sorted by decrementing LC
|
||||||
|
|
||||||
mov hr ar
|
mov hr ar
|
||||||
and HASH_MASK // Completely hash value from AR
|
and HASH_MASK // Completely hash value from AR
|
||||||
@ -57,15 +66,39 @@ mov pm ar
|
|||||||
add 1
|
add 1
|
||||||
mov ar pm
|
mov ar pm
|
||||||
mov ar asr
|
mov ar asr
|
||||||
mov ir pm
|
mov ir pm; declc // Mark element as sorted by decrementing LC
|
||||||
|
|
||||||
bra @BUCKET_SORT
|
bra @BUCKET_SORT
|
||||||
|
|
||||||
|
|
||||||
|
//// ---- MERGE ---- ////
|
||||||
|
|
||||||
$MERGE_INIT
|
$MERGE_INIT
|
||||||
|
|
||||||
|
// HR points to LUT
|
||||||
|
// PC points to start of first bucket
|
||||||
|
// AR points to list
|
||||||
|
mov pc hr // PC is always 0 after bucketsort because FF+1 mod 100 = 0. Imagine that!
|
||||||
|
const FIRST_BUCKET
|
||||||
|
mov ar pc
|
||||||
|
const LIST_START
|
||||||
|
|
||||||
|
$MERGE
|
||||||
|
mov ar ir
|
||||||
|
mov hr asr
|
||||||
|
sub pm
|
||||||
|
mov pc gr
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// If this was not the last bucket, branch back to start of merge
|
||||||
|
sub LAST_BUCKET
|
||||||
|
adn LAST_BUCKET
|
||||||
|
bnz @MERGE
|
||||||
|
|
||||||
|
|
||||||
$END
|
$END
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user