Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @0x00
- ORIGIN = 0xFF8D
- ==Start==
- LDA #1 ; start counting at 1
- {
- PHA ; save A
- JSR Fib
- CMP 0x0200 ; if fib(A)>fib(A-1), stop
- BCC BR
- STA 0x0200
- JSR Printn
- JSR Newline
- PLA ; restore A
- ADC #1 ; increase A by 1
- JMP RE
- }
- {JMP RE}
- ==Fib==
- LDX #1
- LDY #0
- {
- CMP #2
- BCC BR
- SBC #1 ; decrement A
- PHA ; save A
- TXA ; set A to X
- STY 0x0201 ; add Y to A
- CLC
- ADC 0x0201
- STX 0x0201 ; set Y to X
- LDY 0x0201
- TAX ; set X to A
- PLA ; restore A
- JMP RE
- }
- TXA
- RTS
- ==Printn==
- {
- PHA ; save A
- LSR A ; divide A by 10...
- STA 0x0201
- LSR A
- ADC 0x0201
- ROR A
- LSR A
- LSR A
- ADC 0x0201
- ROR A
- ADC 0x0201
- ROR A
- LSR A
- LSR A
- BEQ BR ; stop if A = 0
- JSR Printn ; recursively call Printn
- }
- PLA ; restore A
- {
- CMP #10 ; break if A < 10
- BCC BR
- SBC #10 ; subtract 10 from A
- JMP RE ; and loop
- }
- ORA #0x30 ; ASCII code for '0'
- STA 0x7c00 ; print digit
- RTS
- ==Newline==
- LDA #13
- STA 0x7c00
- RTS
- ==Irq==
- RTI
- @0xFFFC
- DATA Start
- DATA Irq
Add Comment
Please, Sign In to add comment