I got some cpu_timing_tests assembly source code that I was trying to understand what the code was doing. I noticed some branch and jump instructions that branched/jumped to a '-' or a '+'. What does the '-' and '+' mean? Example
bne -
Where does this line branch to if the branch condition is met?
Thanks in advance.
They are relative labels using the next/previous label with that name.
So you could have something like
-
lda $40
bne +
beq -
+
The - would be the previous label named -, and the + would be the next label named +.
There is no limit to how many +/- labels you can create.
ASM6 also lets you use multiple +'s or -'s in succession, so you can have label +, label ++, and label +++ for cases when you need more than one possible label.
Watch out though, sometimes you can screw up and insert new +/- labels between existing code which already has +/- labels, and the old code won't behave the same way as before.
These labels are useful because you don't have to waste time thinking of crazy/unique label names for the smallest of the tasks, where the logic is obvious even without labels.
they are handy but overusing them can lead to hard to read code
Quote:
ASM6 also lets you use multiple +'s or -'s in succession, so you can have label +, label ++, and label +++ for cases when you need more than one possible label.
you can also use text with them.. I use +return a lot (makes more sense with longer examples obviously)
Code:
INC $00
BNE +return
INC $01
+return: RTS
I use nameless labels for loops and branches within subroutines. That's basically it. I would say if the code you are labeling has a well-defined purpose, then put a real name on it (for example, "jsr +" should almost never appear in your code). But if you're doing a simple loop or branch to a sub-section of a routine, don't waste your time.
And something that I think may help if you are having trouble naming your labels is to use dot notation. This allows you to really categorize and narrow down the exact purpose of each piece of code. Also, if you're scanning code, looking at the name of the label you would know pretty much what it does and where it fits in. As an example, I just grabbed a random label from my code, "Main.SpriteMaps.PauseLogo". This tells me that it's mainly accessed by the main loop handler, it's a sprite map, and it defines the pause logo. I guess it's not terribly relevant, but I just thought I'd mention it.