As I understand it, when a BEQ label instruction is carried out following a CMP variable it can be thought of as something like "If variable = 0, JMP label."
Is there a way to cleanly return to the point in your code where the branch was executed like with the JSR and RTS commands?
I was able to figure out a way to do what I want, but the code is a mess:
Code: Select all
LDA gameStartTimer1 STA index1 LDA gameStartTimer2 CMP index1 BEQ Add11 calledFrom1: STA index2 LDA gameStartTimer4 CMP index1 BEQ Add12 calledFrom3: CMP index2 BEQ Add13 calledFrom4: CMP index1 BEQ Add14 calledFrom5: STA index3 ;...... Add11: CLC ADC #$01 CMP arraySize BEQ Set01 calledFrom2: JMP calledFrom1 Add12: CLC ADC #$01 CMP arraySize BEQ Set02 calledFrom6: JMP calledFrom3 Add13: CLC ADC #$01 CMP arraySize BEQ Set03 calledFrom7: JMP calledFrom4 Add14: CLC ADC #$01 CMP arraySize BEQ Set04 calledFrom8: JMP calledFrom5 Set01: LDA #$00 JMP calledFrom2 Set02: LDA #$00 JMP calledFrom6 Set03: LDA #$00 JMP calledFrom7 Set04: LDA #$00 JMP calledFrom8
The multiple Add1 and Set0 subroutines are essentially the same and it would be a lot more clean and efficient to be able to simply reuse them by having them return to the line following branch. Am I missing something extremely basic that would allow me to do this?