tags:

views:

1492

answers:

1

When using inline assembly under MSVC, one is allowed to jump outside of the assembly block by referencing a label in the C/C++ code, as explained in this MSDN article.

Can such thing be done when using inline assembly under GCC?

Here's an example of what I'm trying to accomplish:

__asm__ __volatile__ (
"   /* assembly code */ "
"   jz external_label; "
);

/* some C code */

external_label:
/* C code coninues... */

The compiler, however, complains about "external_label" not being defined.

+3  A: 

What if you define the label with the assembler?

asm("external_label:");


Update: this code seems to work:

#include <stdio.h>

int
main(void)
{
  asm("jmp label");
  puts("You should not see this.");
  asm("label:");

  return 0;
}
Bastien Léonard
That's the first thing I tried, doesn't work either. :/
Vicent Marti
I updated with a sample that seems correct. Does it work for you?
Bastien Léonard
Hmm... This is strange. Your code does compile, however when doing the same thing in mine, the linker still complains about an undefined reference. :/
Vicent Marti
Please post a code example that doesn't work.
Bastien Léonard
Actually, I've just fixed. Turns out you cannot have a 'continue' keyword between the two assembly jumps, or things go messy. :) Thanks!
Vicent Marti