Skip to content

Examples: add even-odd (from issue #198) - #199

Open
github-actions[bot] wants to merge 1 commit into
mainfrom
examples/issue-198
Open

github-actions[bot] wants to merge 1 commit into
mainfrom
examples/issue-198

Conversation

@github-actions

Copy link
Copy Markdown

Generated from issue #198 by the issue-to-pr workflow.

Files:

  • packages/examples/even-odd/even-odd.meta.ts
  • packages/examples/even-odd/even-odd.asm

The submitted source assembles with learn6502 assemble.

Closes #198

Co-authored-by: Pinjontall94 <25357545+Pinjontall94@users.noreply.github.com>
Signed-off-by: Pinjontall94 <25357545+Pinjontall94@users.noreply.github.com>
@github-actions github-actions Bot mentioned this pull request Sep 25, 2026
@JumpLink

JumpLink commented Sep 25, 2026 •

Copy link
Copy Markdown
Owner

Hi @Pinjontall94, thanks for the submission! Nice example :)

My AI claims the following, could you check if that's true?

I ran it with a few different values, and it only gives the right answer for some of them:

Input Expected Result
3 odd (0) 0 ✓
2, 4, 8 even (1) 1 ✓
1 odd (0) 1 ✗
6, 12 even (1) 0 ✗
0 even (1) never finishes

The ror / bcc loop keeps shifting right until it finds the lowest bit that is set, and then checks whether anything is left. So it actually tests "is A a power of two?". That's why 2, 4 and 8 work while 6 and 12 don't. With 0 there is no set bit to find, so the loop runs forever. Also, ror shifts the carry flag into bit 7, so the result can depend on whatever the carry happened to be before.

For even/odd you only need bit 0. lsr shifts it straight into the carry flag, so no loop is needed:

	lda #6
	lsr          ; bit 0 -> carry
	bcs odd      ; carry set = odd
	lda #1       ; even
	jmp end
odd:	lda #0
end:	brk

Would you like to update the example yourself? Just post your new version here and I'll add it to this PR, or let me know and I'll push the fix above under your name. Either way works for us.

@JumpLink

Copy link
Copy Markdown
Owner

Hey @Pinjontall94, sorry about my previous AI mess, I've rewrote my comment above.

@Pinjontall94

Copy link
Copy Markdown

Ugh, agents.md in the repo? Nvm

@JumpLink

JumpLink commented Sep 29, 2026 •

Copy link
Copy Markdown
Owner

@Pinjontall94 Yes, most of the codebase here is still handwritten (apart from autocomplete), but I use AI more and more in my projects these days. But I also understand any skepticism toward it. If you'd like, feel free to close the PR (If you can do that?) if you're not comfortable with that 🤷

@Pinjontall94

Copy link
Copy Markdown

Thx for being understanding and transparent!

This branch has not been deployed

No deployments
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.

[example] even-odd

2 participants