Local Labels
Posted: Tue Dec 16, 2025 3:44 am
Hey fellow 6502 fans
I got a question for y'all. I want to know what y'all do.
Here is my dilemma: I want to have local labels. What does that mean? First, let's do a coding example (from TobuNES):
This is inside my 'compute' sub-routine, under the 'patrol' section. See how I'm labeling them _one, _two, etc? What if I wanted to add code with another label between _four and _five? I would then have to rename all of the _five to _six, and then _six to _seven, all the way down, and then change all the branch locations likewise. Very annoying!
I know that I could use +, ++, -, --, and so on. But to me, that can get confusing very quickly. And if I insert something in between + and ++ then I have to make ++ into +++ and change the branches accordingly. Honestly I'd rather change _five to _six instead, as it is a bit less error prone, seeing that there might be another + or ++ ahead in code and it all seems to blend together.
Also I could use more sub-routines. That would make the main section more clean to look at, and I wouldn't have to worry so much about all of those labels. However, I am also programming sequentially, and I want to keep it all together as much as possible. When I'm trying to see the logic, having it all in the same place is very important.
What I would WANT to do is something with { }. Let's do a proto-code example for what I'm talking about:
These are not exhaustive examples, just wanted to show you the concept. Any label inside of { } does not come outside of it. I couldn't "JMP loop" from outside of those { } because it wouldn't see the "loop" label. I think (though I am not entirely sure) that that would help me with my labels issue. Maybe. It would work similar to + and ++, but it would be in English, so that I can read it logically still.
What do y'all do? How would you tackle a problem like this? I want to know what strategies you all use. After this current project I'm on, I am *highly* considering using CC65 so that I can code 'normally' (aka in C) again. I absolutely love programming in 6502 assembly, but this label issue just makes my code start looking like spaghetti over time.
Thoughts? Ideas? Hints?
Thank you everyone. Hopefully my question is clear enough.
Chad
I got a question for y'all. I want to know what y'all do.
Here is my dilemma: I want to have local labels. What does that mean? First, let's do a coding example (from TobuNES):
Code: Select all
compute_patrol_one
; move enemies horizontally
LDA anim_cnt
AND #$01
BNE compute_patrol_seven
LDX #$00
compute_patrol_two
LDA enem_page+1,X
CLC
ADC enem_page+6,X
STA enem_page+1,X
CMP #$B0 ; right border
BCC compute_patrol_three
LDA #$FF
STA enem_page+4,X
STA enem_page+6,X
compute_patrol_three
CMP #$20 ; left border
BCS compute_patrol_four
LDA #$01
STA enem_page+4,X
STA enem_page+6,X
compute_patrol_four
; check for sway
LDA enem_page+7,X
BEQ compute_patrol_six
LDA enem_page+7,X
CLC
ADC enem_page+6,X
STA enem_page+7,X
CMP #$88 ; one block right
BCC compute_patrol_five
LDA #$FF
STA enem_page+4,X
STA enem_page+6,X
compute_patrol_five
CMP #$78 ; one block left
BCS compute_patrol_six
LDA #$01
STA enem_page+4,X
STA enem_page+6,X
compute_patrol_six
; repeat for all enemies
TXA
CLC
ADC #$08
TAX
CMP #$80
BNE compute_patrol_two
compute_patrol_seven
RTS
I know that I could use +, ++, -, --, and so on. But to me, that can get confusing very quickly. And if I insert something in between + and ++ then I have to make ++ into +++ and change the branches accordingly. Honestly I'd rather change _five to _six instead, as it is a bit less error prone, seeing that there might be another + or ++ ahead in code and it all seems to blend together.
Also I could use more sub-routines. That would make the main section more clean to look at, and I wouldn't have to worry so much about all of those labels. However, I am also programming sequentially, and I want to keep it all together as much as possible. When I'm trying to see the logic, having it all in the same place is very important.
What I would WANT to do is something with { }. Let's do a proto-code example for what I'm talking about:
Code: Select all
; first loop
{
LDX #$00
LDA #$00
loop:
STA page_one,X
INX
BNE loop
}
; second loop
{
LDX #$00
LDA #$80
loop:
STA page_two,X
INX
BNE loop
}
What do y'all do? How would you tackle a problem like this? I want to know what strategies you all use. After this current project I'm on, I am *highly* considering using CC65 so that I can code 'normally' (aka in C) again. I absolutely love programming in 6502 assembly, but this label issue just makes my code start looking like spaghetti over time.
Thoughts? Ideas? Hints?
Thank you everyone. Hopefully my question is clear enough.
Chad