English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Asm / Hardware

 
 
Thread Tools
Old Yesterday, 21:19   #1
dansalvato
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
I usually use
.0
and 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
A label written as
:
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.
dansalvato is offline  
Old Yesterday, 22:07   #2
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,388
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.
meynaf is offline  
Old Yesterday, 22:56   #3
a/b
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.
a/b is offline  
Old Today, 11:51   #4
phx
Natteravn
 
phx's Avatar
 
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 (+).
phx is offline  
Old Today, 19:50   #5
paraj
Registered User
 
paraj's Avatar
 
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
I'm sure you'll be more disciplined, and write better code, but I'm not and can't.

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
paraj is offline  
Old Today, 20:30   #6
dansalvato
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.
dansalvato is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 21:25.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.08583 seconds with 15 queries