www.digitalmars.com         C & C++   DMDScript  

D - inline asm local identifiers

reply "Sean L. Palmer" <palmer.sean verizon.net> writes:
It seems the inline assembler doesn't support local identifiers (for labels)
of the form  ident:

void foo()
{
    asm
    {
            mov ecx, 4;
         loop:            // error about malformed identifier
            dec ecx;
            jns  loop;
    }

    // blah.blah...

    asm
    {
            mov ecx, 4;
         loop:               // if you remove the  's, this errors due to
duplicate label
            dec ecx;
            jns  loop;
    }
}

Is this a planned feature?  Or should labels be limited in scope to the asm
block they're declared in?  Or should I just grin and bear it?  ;)

Sean
Apr 06 2003
parent reply "Walter" <walter digitalmars.com> writes:
' ' isn't supported as an identifier character, and 'loop' is an
instruction, not a label.

"Sean L. Palmer" <palmer.sean verizon.net> wrote in message
news:b6qlmq$ktb$1 digitaldaemon.com...
 It seems the inline assembler doesn't support local identifiers (for

 of the form  ident:

 void foo()
 {
     asm
     {
             mov ecx, 4;
          loop:            // error about malformed identifier
             dec ecx;
             jns  loop;
     }

     // blah.blah...

     asm
     {
             mov ecx, 4;
          loop:               // if you remove the  's, this errors due to
 duplicate label
             dec ecx;
             jns  loop;
     }
 }

 Is this a planned feature?  Or should labels be limited in scope to the

 block they're declared in?  Or should I just grin and bear it?  ;)

 Sean

Apr 07 2003
parent reply "Sean L. Palmer" <palmer.sean verizon.net> writes:
Ok, sorry, loop was a bad choice for label identifier.  It was just for
example purposes;  the actual label was more like  startsse2:

So you didn't say, is label scope staying like this?   ident means unique
local label in every standard macro assembler I can remember.  Can you
suggest anything?  If not, I'll just stick to using unique identifiers, but
it makes cut-and-paste much harder.  D inline asm doesn't support macros
AFAIK.

What if we could write 'private mylabel:' to indicate the name isn't visible
outside the asm block?

Sean

"Walter" <walter digitalmars.com> wrote in message
news:b6ss2n$jio$2 digitaldaemon.com...
 ' ' isn't supported as an identifier character, and 'loop' is an
 instruction, not a label.

 "Sean L. Palmer" <palmer.sean verizon.net> wrote in message
 news:b6qlmq$ktb$1 digitaldaemon.com...
 It seems the inline assembler doesn't support local identifiers (for

 of the form  ident:

 void foo()
 {
     asm
     {
             mov ecx, 4;
          loop:            // error about malformed identifier
             dec ecx;
             jns  loop;
     }

     // blah.blah...

     asm
     {
             mov ecx, 4;
          loop:               // if you remove the  's, this errors due


 duplicate label
             dec ecx;
             jns  loop;
     }
 }

 Is this a planned feature?  Or should labels be limited in scope to the

 block they're declared in?  Or should I just grin and bear it?  ;)

 Sean


Apr 07 2003
next sibling parent "Chris Paulson-Ellis" <chrispe tenornetworks.com> writes:
"Sean L. Palmer" <palmer.sean verizon.net> wrote in message
news:b6tqt9$1910$1 digitaldaemon.com...
 Can you
 suggest anything?  If not, I'll just stick to using unique identifiers,

 it makes cut-and-paste much harder.

In MIPS assembler (not that I would wish to encourage much borrowing from it), you can use a number for a label, say 1:, and then branch to the number either backwards, or forwards by saying 1b or 1f. In my code, most of the labels are 1:, with 2: 3: etc used for nested loops, loop breaks, and such. At first I didn't like it, but it does save you from having to think up local label names. Here is an example (the 1: label is for the loop, and the 2: label implements a conditional block within the loop). ... /* Write value to all locations bytewise. */ 1: sb s4, (t0) /* let us only kick the watchdog every 64K! */ li t8, 0xFFFF and t8, t0, t8 bne t8, zero, 2f nop kick_watchdog (t8, t9) 2: bne t0, s7, 1b addiu t0, 1 ... Chris.
Apr 08 2003
prev sibling parent reply "Walter" <walter digitalmars.com> writes:
"Sean L. Palmer" <palmer.sean verizon.net> wrote in message
news:b6tqt9$1910$1 digitaldaemon.com...
 So you didn't say, is label scope staying like this?   ident means unique
 local label in every standard macro assembler I can remember.  Can you
 suggest anything?  If not, I'll just stick to using unique identifiers,

 it makes cut-and-paste much harder.  D inline asm doesn't support macros
 AFAIK.

 What if we could write 'private mylabel:' to indicate the name isn't

 outside the asm block?

The need for uniquely generated names arises from macro expansion. The D inline assembler isn't a *macro* assembler, as it does not support text substitution macros. Labels in asm blocks have the same scope as other labels, and they are unique to the function they are in (unlike typical macro assemblers). Also, in order to fit successfully with the D compilation model, the inline assembler has to match D's use of tokens, etc. This is why it is case sensitive, rather than insensitive like typical macro assemblers.
Apr 08 2003
parent "Sean L. Palmer" <palmer.sean verizon.net> writes:
Ok.  Point taken.

Sean

"Walter" <walter digitalmars.com> wrote in message
news:b6vafl$2d1f$1 digitaldaemon.com...
 The need for uniquely generated names arises from macro expansion. The D
 inline assembler isn't a *macro* assembler, as it does not support text
 substitution macros. Labels in asm blocks have the same scope as other
 labels, and they are unique to the function they are in (unlike typical
 macro assemblers).

 Also, in order to fit successfully with the D compilation model, the

 assembler has to match D's use of tokens, etc. This is why it is case
 sensitive, rather than insensitive like typical macro assemblers.

Apr 08 2003