6502 provides the following functions to control the flow of a program, that is, to change the PC register.
- Absolute absolute
- Jmp indirect
- Relative instructions Bxx
- Absolute JSR with later version of RTS
- BRK or another IRQ with a later version of RTI (or RTS if you pull
.P from the stack) - Pushing two values โโonto the stack and then RTS / RTI
- Hardware reset causes a jump through the reset vector
What is it. If you need something more complex, you need to create it using one or more of the above.
One way to implement the switch statement is to create a table of pointers to all the routines involved in the switch statement. Separate them according to the low bytes of the routines, and then the high bytes:
switchtab_lo .db >routine1, >routine2, >routine3
switchtab_hi .db <routine1, <routine2, <routine3
(I cannot remember if> means low byte or high byte, and different assemblers may have different syntax)
and then assuming that the value you want to include is in .X, and vector is two bytes that do not start at the end of the page (to avoid an indirect JMP error), and you make sure that this is a valid value:
lda switchtab_lo,X sta vector lda switchtab_hi,X sta vector+1 jmp (vector)
It is tiring to do this every time you need to switch, but why exactly high-level languages โโwere invented.
source share