public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* local labels
@ 2001-09-17 16:58 Ben Elliston
  2001-09-18  4:31 ` Nick Clifton
  0 siblings, 1 reply; 4+ messages in thread
From: Ben Elliston @ 2001-09-17 16:58 UTC (permalink / raw)
  To: binutils

The GAS documentation states that there are ten local labels
available: `0' to `9'.  I have been able to use local labels with
higher values, like `99'.  Is the documentation out of date in this
regard?

Ben

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: local labels
  2001-09-17 16:58 local labels Ben Elliston
@ 2001-09-18  4:31 ` Nick Clifton
  2001-09-18 17:38   ` Hans-Peter Nilsson
  0 siblings, 1 reply; 4+ messages in thread
From: Nick Clifton @ 2001-09-18  4:31 UTC (permalink / raw)
  To: Ben Elliston; +Cc: binutils

Hi Ben,

> The GAS documentation states that there are ten local labels
> available: `0' to `9'.  I have been able to use local labels with
> higher values, like `99'.  Is the documentation out of date in this
> regard?

Indeed it is.  In fact the whole subsection is in need of a good
rewrite.  Here is my suggestion.  Any comments ?

Cheers
        Nick

==================================================================

Local Symbol Names
------------------

   Local symbols help compilers and programmers use names temporarily.
They create symbols which are guaranteed to be unique over the entire
scope of the input source code and which can be referred to by a simple
notation.  To define a local symbol, write a label of the form `N:'
(where N represents any positive integer).  To refer to the most recent
previous definition of that symbol write `Nb', using the same number as
when you defined the label.  To refer to the next definition of a local
label, write `Nf'-- The `b' stands for"backwards" and the `f' stands
for "forwards".

   There is no restriction on how you can use these labels, and you can
reuse them too.  So that it is possible to repeatedly define the same
local label (using the same number `N'), although you can only refer to
the most recently defined local label of that number (for a backwards
reference) or the next definition of a specific local label for a
forward reference.  It is also worth noting that the first 10 local
labels (`0:'...`9:') are implemented in a slightly more efficient
manner than the others.

   Here is an example:

     1:        branch 1f
     2:        branch 1b
     1:        branch 2f
     2:        branch 1b

   Which is the equivalent of:

     label_1:  branch label_3
     label_2:  branch label_1
     label_3:  branch label_4
     label_4:  branch label_3

   Local symbol names are only a notational device.  They are
immediately transformed into more conventional symbol names before the
assembler uses them.  The symbol names stored in the symbol table,
appearing in error messages and optionally emitted to the object file.
The names are constructed using these parts:

`L'
     All local labels begin with `L'. Normally both `as' and `ld'
     forget symbols that start with `L'. These labels are used for
     symbols you are never intended to see.  If you use the `-L' option
     then `as' retains these symbols in the object file. If you also
     instruct `ld' to retain these symbols, you may use them in
     debugging.

`NUMBER'
     This is the number that was used in the local label definition.
     So if the label is written `55:' then the number is `55'.

`C-B'
     This unusual character is included so you do not accidentally
     invent a symbol of the same name.  The character has ASCII value
     of `\002' (control-B).

`_ordinal number_'
     This is a serial number to keep the labels distinct.  The first
     definition of `0:' gets the number `1'.  The 15th definition of
     `0:' gets the number `15', and so on.  Likewise the first
     definition of `1:' gets the number `1' and its 15th defintion gets
     `15' as well.

   So for example, the first `1:' is named `L1C-B1', the 44th `3:' is
named `L3C-B44'.

Dollar Local Labels
-------------------

   `as' also supports an even more local form of local labels called
dollar labels.  These labels go out of scope (ie they become undefined)
as soon as a non-local label is defined.  Thus they remain valid for
only a small region of the input source code.  Normal local labels, by
contrast, remain in scope for the entire file, or until they are
redefined by another occurrence of the same local label.

   Dollar labels are defined in exactly the same way as ordinary local
labels, except that instead of being terminated by a colon, they are
terminated by a dollar sign.  eg `55$'.

   They can also be distinguished from ordinary local labels by their
transformed name which uses ASCII character `\001' (control-A) as the
magic character to distinguish them from ordinary labels.  Thus the 5th
defintion of `6$' is named `L6C-A5'.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: local labels
  2001-09-18  4:31 ` Nick Clifton
@ 2001-09-18 17:38   ` Hans-Peter Nilsson
  2001-09-19  0:54     ` Nick Clifton
  0 siblings, 1 reply; 4+ messages in thread
From: Hans-Peter Nilsson @ 2001-09-18 17:38 UTC (permalink / raw)
  To: Nick Clifton; +Cc: Ben Elliston, binutils

On 18 Sep 2001, Nick Clifton wrote:
> In fact the whole subsection is in need of a good
> rewrite.  Here is my suggestion.  Any comments ?

As a whole, great.  If only all the documentation was like this.
Though the use of control characters is an implementation
detail.  I'm not sure it should be exposed to the
documentation-reading masses.

brgds, H-P

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: local labels
  2001-09-18 17:38   ` Hans-Peter Nilsson
@ 2001-09-19  0:54     ` Nick Clifton
  0 siblings, 0 replies; 4+ messages in thread
From: Nick Clifton @ 2001-09-19  0:54 UTC (permalink / raw)
  To: Hans-Peter Nilsson; +Cc: Ben Elliston, binutils

Hi Hans-Peter,

> As a whole, great.  If only all the documentation was like this.
> Though the use of control characters is an implementation
> detail.  I'm not sure it should be exposed to the
> documentation-reading masses.

In this particular case I think that it is useful, since the labels
containing the control characters can be reported in error messages,
or appear in the object file (if -L is used).

Cheers
        Nick

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2001-09-19  0:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-09-17 16:58 local labels Ben Elliston
2001-09-18  4:31 ` Nick Clifton
2001-09-18 17:38   ` Hans-Peter Nilsson
2001-09-19  0:54     ` Nick Clifton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).