mirror of
https://github.com/mre/mos6502.git
synced 2024-12-01 11:51:51 +00:00
e88c971625
* Add assembly example code This should make it easier for beginners to understand how to test this emulator. * cleanup * fix typo
34 lines
731 B
Plaintext
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
|