I am trying to understand control flow in 6502 assembly.
Say I have the following code:
ControlFlow:
lda mem
cmp #1
bne .sub_one
cmp #2
bne .sub_two
.sub_one:
; sub routine one goes here
jmp .done ; <-------------- without this jmp, .sub_two will execute
.sub_two:
; sub routine two goes here
.done:
rts
Personally, I would love a switch statement or some other control flow structure. The JMP above concerns me as well. It seems like there is a better way to handle multiple cases without this type of spaghetti code.
There is no better way actually but there might be an improvement like calling the FlowControl as a subroutine and returning with RTS.
This is the main flow.
Here is the sub routine.
if sub routines are too long, you need to use JMPs as mentioned before.
That's how it is done and unfortunately, there is no better way. This applies to many assembly languages if not all.