blob: 14860c1fa2247d0d2efa4ebc71090f4e1c630e40 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
|
<div class="subsection-level-extent" id="Asm-Labels"> <div class="nav-panel"> <p> Next: <a href="explicit-register-variables" accesskey="n" rel="next">Variables in Specified Registers</a>, Previous: <a href="constraints" accesskey="p" rel="prev">Constraints for <code class="code">asm</code> Operands</a>, Up: <a href="using-assembly-language-with-c" accesskey="u" rel="up">How to Use Inline Assembly Language in C Code</a> [<a href="index#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="indices" title="Index" rel="index">Index</a>]</p> </div> <h1 class="subsection" id="Controlling-Names-Used-in-Assembler-Code"><span>6.47.4 Controlling Names Used in Assembler Code<a class="copiable-link" href="#Controlling-Names-Used-in-Assembler-Code"> ¶</a></span></h1> <p>You can specify the name to be used in the assembler code for a C function or variable by writing the <code class="code">asm</code> (or <code class="code">__asm__</code>) keyword after the declarator. It is up to you to make sure that the assembler names you choose do not conflict with any other assembler symbols, or reference registers. </p> <h1 class="subsubheading" id="Assembler-names-for-data"><span>Assembler names for data<a class="copiable-link" href="#Assembler-names-for-data"> ¶</a></span></h1> <p>This sample shows how to specify the assembler name for data: </p> <div class="example smallexample"> <pre class="example-preformatted" data-language="cpp">int foo asm ("myfoo") = 2;</pre>
</div> <p>This specifies that the name to be used for the variable <code class="code">foo</code> in the assembler code should be ‘<samp class="samp">myfoo</samp>’ rather than the usual ‘<samp class="samp">_foo</samp>’. </p> <p>On systems where an underscore is normally prepended to the name of a C variable, this feature allows you to define names for the linker that do not start with an underscore. </p> <p>GCC does not support using this feature with a non-static local variable since such variables do not have assembler names. If you are trying to put the variable in a particular register, see <a class="ref" href="explicit-register-variables">Variables in Specified Registers</a>. </p> <h1 class="subsubheading" id="Assembler-names-for-functions"><span>Assembler names for functions<a class="copiable-link" href="#Assembler-names-for-functions"> ¶</a></span></h1> <p>To specify the assembler name for functions, write a declaration for the function before its definition and put <code class="code">asm</code> there, like this: </p> <div class="example smallexample"> <pre class="example-preformatted" data-language="cpp">int func (int x, int y) asm ("MYFUNC");
int func (int x, int y)
{
/* <span class="r">…</span> */</pre>
</div> <p>This specifies that the name to be used for the function <code class="code">func</code> in the assembler code should be <code class="code">MYFUNC</code>. </p> </div> <div class="nav-panel"> <p> Next: <a href="explicit-register-variables">Variables in Specified Registers</a>, Previous: <a href="constraints">Constraints for <code class="code">asm</code> Operands</a>, Up: <a href="using-assembly-language-with-c">How to Use Inline Assembly Language in C Code</a> [<a href="index#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="indices" title="Index" rel="index">Index</a>]</p> </div><div class="_attribution">
<p class="_attribution-p">
© Free Software Foundation<br>Licensed under the GNU Free Documentation License, Version 1.3.<br>
<a href="https://gcc.gnu.org/onlinedocs/gcc-13.1.0/gcc/Asm-Labels.html" class="_attribution-link">https://gcc.gnu.org/onlinedocs/gcc-13.1.0/gcc/Asm-Labels.html</a>
</p>
</div>
|