Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7956 Discussions

Jumping to Labels in Inline Assembly

Elbert_John_A__Orozc
3,997 Views

Can I use labels in inline assembly such as this:

int main()

{

        __asm__(

                      "jmp label_1;"

                      );

        label_1:

        return 0;

}

Mine doesn't seem to compile somehow...

0 Kudos
24 Replies
Casey
Beginner
259 Views

Sergey Kostrov wrote:

It was already explained by Elbert that Intel C++ compiler version 2013 integrated with VS 2012 under Windows was actually used. Even if initial test-case created some confusion I don't think that Elbert is interested in Linux, GCC and AT&T style of inline assembler. Elbert, am I correct?

Sergey,

   I realized from the beginning that the windows compiler was being used and had no intentions of having someone switch platforms.  I posted my test case (which works) purely to contribute to the thread.  It was not until Jim's followup post to me that I did some digging and learned that the handling of inline assembly is different between windows and linux, making the test case platform specific -- knowledge of which I also contributed to this thread.  There aren't too many issues where the platform is going to matter but this indeed is one of them.  BTW, I never mentioned GCC in my post, my test case compiles against Intel's icc (Which you can see in my post), though the __asm__ is assembled behind the scenes by a GNU assembler, this is not something you interact with directly.  I also acknowledge that it was *my* test case that caused confusion since I posted something that met the OP's requirements but (unknowingly) did not work on his platform.  I'll also reiterate that the AT&T style assembler was produced by icc and only posted to show that correct assembly was produced from the test case -- it does not matter what format it is in for that confirmation.

0 Kudos
Elbert_John_A__Orozc
259 Views

Thank you everyone for the posts. It is of great help to me. I've been doing assembly for quite some time using LLVM on OS X and have been acquainted using AT&T style of assembly. I am recently studying inline assembly in windows through visual studio for a project and saw intel compiler supports AT&T style, which I believe will make things quite easier for me. 

0 Kudos
SergeyKostrov
Valued Contributor II
259 Views
Some issues related to the subject of the thread are dated back to 2004 year. This is what I found in Release Notes for Intel C++ compiler version 7.1 Update 29: ... In an inline asm block, the conditional jumps, jcxz and jecxz, should not be used to jump to another function. For instance, jcxz and jecxz will not have the correct target location in the following code: int main(void); void DoneThat(void); void BeenThere(void); int main() { BeenThere(); return 0; } void BeenThere() { __asm jcxz DoneThat __asm jecxz DoneThat } void DoneThat() { exit(0); } ... Note: This is only for everyone's knowledge. Thanks.
0 Kudos
Marián__VooDooMan__M
New Contributor II
259 Views

Sergey Kostrov wrote:

Some issues related to the subject of the thread are dated back to 2004 year. This is what I found in Release Notes for Intel C++ compiler version 7.1 Update 29:

...
In an inline asm block, the conditional jumps, jcxz and jecxz, should
not be used to jump to another function. For instance, jcxz and jecxz
will not have the correct target location in the following code:

This makes sense to me. If it were implemented, only the C code would work. But in C++ compiler generates code for calling destructors of instances of non-POD classes/structs allocated on the stack, and even in C the stack needs to be rolled back. The only exception are C++ exceptions that work accross function calls, but compiler takes care of it and knows about this "nearly non-standard" event (the throw), unlike event of jump into another function, about which compiler knows nothing. This technique could corrupt stack and lead to program unstability. Though, it is possible to do this without corrupting the stack, but this is what I call a big no-no and a bad coding practice.

0 Kudos
Reply