Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.programming > #2134
| From | Nomen Nescio <nobody@dizum.com> |
|---|---|
| Newsgroups | comp.programming |
| Subject | Re: Implementing Local Labels in an Assembler |
| References | <k1q3pr$4gj$1@dont-email.me> |
| Message-ID | <16a4802da50f44519c40a60aaa7d5b05@dizum.com> (permalink) |
| Date | 2012-08-31 18:34 +0200 |
| Organization | mail2news@dizum.com |
What is the benefit of local labels? Do you really mean to allow duplicate labels or do you just not want to export certain labels to the linker, or something else? If duplicate labels, you could make a rule that the closest reference wins. I really don't like duplicate labels because I work on huge pieces of code and these kinds of stupid assembly tricks make doing that harder than it has to be. If you have a way you can clearly understand what is inside a function and what isn't, you could generate a unique symbol table name by function.local_label_name when the user codes local_label_name. If not exporting the label to the linker, I should think you can do that automagically, but then I don't know how you've decided to do your symbol table management and elf header generation (or whatever you have to export to the linker in your OS). In my case I simply don't export any labels unless there's an assembler directive coded to do so and that includes functions as well (all functions are local unless declared otherwise). I find requiring directives is a lot more obvious and efficient than assuming everything is exportable, and it cuts down dramatically on useless externs. I've seen other assemblers that use various syntax to declare local labels ddepending on whether there are forward or backward references to them. I can't remember which, but check nasm and fasm. Doc and source is available for both. The system whichever of them uses seems workable and the authors are still around to ask questions. "BartC" <bc@freeuk.com> wrote: > > > "Charles Richmond" <numerist@aquaporin4.com> wrote in message > news:k1os71$8om$1@dont-email.me... > > Just as an exercise for myself, I am attempting to write an assembler for > > an old 8-bit microprocessor. The assembler will be written in C. > > > > I am at a loss to figure out how to handle local labels. > > > Can anyone suggest how I might handle local labels, or point me to some > > explanation on the internet of how to do this??? > > I had a similar problem, with labels that were defined in the inline > assembler of a HLL had file-scope, which meant each function needed a unique > set of label names (which was a PITA). > > So I used a scheme where local labels were prefixed with "#": #abc, #123, > etc (with the extra advantage I could use numeric labels, so I didn't need > to be so creative...). > > The compiler then changed each "#" prefix to an identifier unique to the > function; this could have been the function name, but I chose an ordinal > value that incremented with each function, to keep things compact: so > f33_abc, f33_123, etc. > > > I am at a loss to figure out how to handle local labels. My understanding > > is: A local label in this assembly language is one that begins with a "$" > > (dollar sign). Such labels only have the scope of between two non-local > > labels. So I can't just toss them into the symbol table with the other > > labels, unless there is some special processing here. > > > > OK, so a label without the special prefix effectively partitions code into > 'functions', although I would be tempted to use a special designator for > this, such as a 'function' directive; I assume you can customise the syntax > of this assembler. > > That last non-$ label (or the 'function' directive if it also has a name), > is used to generate a unique prefix which can be added to the following > $labels. > > This would obviously be done both for $-labels which are actual labels, and > those which are used as operands (jump instructions and such). > > The main problem might be if you want to refer to those $-labels from > outside that block; using a separate 'function' directive would have the > advantage of allowing you to use ordinary labels for this purpose. > > -- > Bartc >
Back to comp.programming | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Implementing Local Labels in an Assembler "Charles Richmond" <numerist@aquaporin4.com> - 2012-08-30 18:15 -0500
Re: Implementing Local Labels in an Assembler Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-08-30 16:35 -0700
Re: Implementing Local Labels in an Assembler James Harris <james.harris.1@gmail.com> - 2012-08-31 00:07 -0700
Re: Implementing Local Labels in an Assembler "BartC" <bc@freeuk.com> - 2012-08-31 11:29 +0100
Re: Implementing Local Labels in an Assembler Nomen Nescio <nobody@dizum.com> - 2012-08-31 18:34 +0200
Re: Implementing Local Labels in an Assembler "BartC" <bc@freeuk.com> - 2012-08-31 20:30 +0100
Re: Implementing Local Labels in an Assembler Anonymous <nobody@remailer.paranoici.org> - 2012-09-02 09:10 +0000
Re: Implementing Local Labels in an Assembler "Charles Richmond" <numerist@aquaporin4.com> - 2012-08-31 14:07 -0500
Re: Implementing Local Labels in an Assembler "BartC" <bc@freeuk.com> - 2012-08-31 20:27 +0100
csiph-web