Skip to content

Add bubble sort example#123

Merged
mre merged 3 commits intoadd-interrupt-supportfrom
add-bubble-sort-example
Jan 8, 2026
Merged

Add bubble sort example#123
mre merged 3 commits intoadd-interrupt-supportfrom
add-bubble-sort-example

Conversation

@mre
Copy link
Owner

@mre mre commented Jan 4, 2026

Adds another example, a simple bubble sort algorithm, to the repo with the goal to demonstrate how interrupt handling works (used for halting the program after execution).

The goal was to document as much of the algorithm and scaffolding code as possible to help beginners get started with the library.

Depends on #122, because we use the new interrupt handling.
Closes #35

mre added 2 commits January 4, 2026 17:25
This adds a new bubble sort example implementation.
Array is stored at $20-$2F and supports up to 16 elements.

Demonstrates:
- Zero-page indexed addressing
- Conditional branching and loops
- Interactive input/output with the emulator
- Add early exit for n<2 in Rust wrapper (workaround for emulator bug)
- Keep assembly early exit for documentation
- Add extensive comments to assembly code
- Handle edge case: 1-element arrays now work correctly

Note: There appears to be an emulator bug where the BCC instruction
after CMP doesn't branch correctly for n=1. This needs investigation
in a separate issue.
@mre mre requested a review from omarandlorraine January 4, 2026 20:15
Copy link
Collaborator

@omarandlorraine omarandlorraine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That all seems right to me

@mre
Copy link
Owner Author

mre commented Jan 8, 2026

Thanks for the review. 👍

@mre mre merged commit 910878c into add-interrupt-support Jan 8, 2026
7 checks passed
@mre mre deleted the add-bubble-sort-example branch January 8, 2026 12:30
mre added a commit that referenced this pull request Feb 6, 2026
This adds a new bubble sort example implementation.
Array is stored at $20-$2F and supports up to 16 elements.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants