Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.programming > #2132

Re: Implementing Local Labels in an Assembler

From "BartC" <bc@freeuk.com>
Newsgroups comp.programming
Subject Re: Implementing Local Labels in an Assembler
Date 2012-08-31 11:29 +0100
Organization A noiseless patient Spider
Message-ID <k1q3pr$4gj$1@dont-email.me> (permalink)
References <k1os71$8om$1@dont-email.me>

Show all headers | View raw



"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


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