![]() |
![]() |
#1 |
Registered User
Join Date: Jun 2009
Location: United States
Posts: 67
|
How do you prefer to write anonymous/discarded labels?
Writing for 68k, my code is full of tiny branches, stuff like this:
Code:
tst.w d0 bpl .0 neg.w d0 .0: rts .0and increment the number for each label in the function. This only goes for local labels that aren't worth naming—for larger chunks of logic, I try to give them descriptive names. But a while back, I did some 6502 Assembly, and I really enjoyed the convention for anonymous labels. Most 6502 assemblers (including the 6502 module for vasm) allow for this kind of anonymous label, with slightly varying syntax: Code:
cmp #0 bpl :+ eor #$ff inc : rts :denotes an anonymous label, which can be used more than once in the function. Then, a +means to branch to the next anonymous label. A -would branch to the previous one. IMO, it's really nice to see the +or -and instantly know whether you're branching forwards or backwards. I wish there was an equivalent for 68k for simple use cases like this. |
![]() |
![]() |
#2 |
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,390
|
I do local labels depending on what they are, f.e. .loop.
In your examples, they could be .pos and .ret ; i find this more readable. |
![]() |
![]() |
#3 |
Registered User
Join Date: Jun 2016
Location: europe
Posts: 1,096
|
I also use meaningfull names and/or abbreviations. It's easier to read and understand when you get back to old code, and could also be a semi-decent substitute for comments (doesn't mean you don't need them, just that if you put more effort into names/labels/..., they're not needed as much).
I rarely need to write a lot of code fast, I typically go through several optimization phases and lots of tinkering, so taking time to write a few extra characters works fine for me. |
![]() |
![]() |
#4 |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,577
|
I agree with the two previous posts and I will probably not add anonymous labels to the mot-syntax module.
But you can always recompile vasm to use a different syntax-module with the m68k backend. Even the oldstyle-syntax one, originally intended for 8-bit architectures, which offers you the anonymous ':' labels. Or you could use the std-syntax module, with the syntax known from the GNU-assembler. There you have anonymous labels with digits from 1 to 9, followed by 'b' for next label backwards (-) or 'f' for forward (+). |
![]() |
![]() |
#5 |
Registered User
Join Date: Feb 2017
Location: Denmark
Posts: 1,310
|
While I agree in principle it might be nice to have a quick shorthand while writing the code, I always regret it when coming back, and hate seeing more than a few anonymous labels (especially in other peoples code
![]() One forward and one backward label only is OK, but anything more that gets messy real quick. Here's a snippet I dug out where I used anonymous labels to show what I mean: Code:
ReadKey: @Load: lda InputText bne :+ jmp CHRIN : inc @Load + 1 bne :+ inc @Load + 2 : cmp #$61 ; ASCII lower case 'a' bcc :++ cmp #$7a+1 ; ASCII lower case 'z' bcs :+ and #$df : rts : cmp #$5c ; ASCII backslash '\' bne :+ lda #'\' rts : cmp #$5f ; ASCII underscore '_' bne :+ lda #'_' : rts FWIW In you're concrete example - and I know this doesn't necessarily generalize - one code module might benefit from a macro like: Code:
ABS MACRO tst.\0 \1 bpl \@ neg.\0 \1 \@ ENDM |
![]() |
![]() |
#6 |
Registered User
Join Date: Jun 2009
Location: United States
Posts: 67
|
I try to use descriptive local labels for key logical branches, and I use one-letter labels (.l, .n, .e) for common obvious things like loop, next, end.
But there are plenty of cases (like paraj's example) with a lot of small, obvious comparisons where it's much easier to let your eyes follow the code than it is to parse label names. Those are the cases where I use non-descriptive labels like .0, .1, etc. edit: I recognize paraj's example is one to demonstrate where anonymous labels can get confusing. Here's how I'd probably write the labels there. I only kept one anonymous label, but it's not hard to imagine a function 10x as long as this, where this would become 10 anonymous labels, and the benefit to readability is compounded. Code:
ReadKey: @Load: lda InputText bne .go jmp CHRIN .go: inc @Load + 1 bne :+ inc @Load + 2 : cmp #$61 ; ASCII lower case 'a' bcc .bcksl cmp #$7a+1 ; ASCII lower case 'z' bcs .e and #$df .e: rts .bcksl: cmp #$5c ; ASCII backslash '\' bne .undsc lda #'\' rts .undsc: cmp #$5f ; ASCII underscore '_' bne .e2 lda #'_' .e2: rts Last edited by dansalvato; Yesterday at 22:02. |
![]() |
![]() |
#7 |
Registered User
Join Date: Mar 2018
Location: Hastings, New Zealand
Posts: 2,859
|
I always use descriptive labels, as they help to document the code and
avoid mistakes. In your example it would be something like:- Code:
tst.w d0 bpl .done neg.w d0 .done: rts |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
vasm - anonymous labels? | pants | Coders. Asm / Hardware | 3 | 01 October 2017 00:40 |
What Crunchers do you guys prefer? | Plagueis/KRX | Coders. General | 67 | 30 July 2014 23:20 |
Which would prefer handheld or laptop | Vars191 | Amiga scene | 5 | 06 June 2011 23:13 |
Anonymous contributions | TCD | HOL contributions | 2 | 24 November 2010 06:42 |
Civilization Anonymous | oldpx | Retrogaming General Discussion | 0 | 29 August 2005 00:21 |
|
|