Skip to content

Commit 5616068

Browse files
committed
qsort mk8
1 parent dfca247 commit 5616068

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

asm/qsort_mk8.asm

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,13 @@ sort:
6363
pop-s to right to last
6464
pop-s to left to first
6565
# if length(array) > 1
66-
load right sub left jz sort_end
67-
sub 1 jz sort_end
66+
load right sub left jz sort_end jn sort_end
6867
# select first element as the pivot
6968
peek left to pivot
7069
# while left <= right
7170
loop1: load right sub left jn loop1_end
7271
# while array[left] < pivot
73-
loop2: peek left to tmp load pivot sub tmp jn loop2_end
72+
loop2: peek left to tmp load pivot sub tmp jn loop2_end jz loop2_end
7473
inc left
7574
jmp loop2 loop2_end:
7675
# while array[right] > pivot

python/asm.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ def compile(text, opcodes: dict[str,int], with_labels=False) -> list[int]:
3939
tokens = []
4040
kv = {}
4141
current_label = "_"
42-
for line in lines:
42+
for i,line in enumerate(lines):
43+
# prepare explanation
44+
line_num = i+1
45+
pc = len(tokens)
46+
#print(f"{pc:3} | {line}")
4347
# remove inline comments
4448
line = re.sub(CFG['inline_comment_re'], '', line)
4549
# split into tokens

0 commit comments

Comments
 (0)