1
0
mirror of https://github.com/mre/mos6502.git synced 2024-06-08 14:29:34 +00:00
mre-mos6502/examples/asm/euclid/euclid.a65
Matthias Endler e88c971625
Add assembly example code (#80)
* Add assembly example code

This should make it easier for beginners to understand
how to test this emulator.

* cleanup

* fix typo
2023-06-20 10:32:28 +02:00

34 lines
731 B
Plaintext

; euclid.a65
; A program to find the greatest common divisor of two numbers
.ORG $1000
; .algo
LDA $00 ; Load from F to A
; .algo_
sec ; Set carry flag
SBC $01 ; Subtract S from the number in A (from F)
BEQ end ; Jump to .end if the difference is zero
BMI swap ; Jump to .swap if the difference is negative
STA $00 ; Load A to F
JMP algo_ ; Jump to .algo_
; .end
end:
LDA $00 ; Load from F to A
BRK ; Break (end program)
; .swap
swap:
LDX $00 ; Load F to X
LDY $01 ; Load S to Y
STX $01 ; Store X to S
STY $00 ; Store Y to F
JMP algo ; Jump to .algo
algo:
JMP algo ; Infinite loop to prevent program from ending
algo_:
JMP algo_ ; Infinite loop to prevent program from ending