title: Use an assembly function in C without call and ret and store the return address in register
body: <p>I wrote a function in assembly and now I want to use it in C
  but my function is not for '<code>call</code>' and '<code>ret</code>' and the return address will be store in a register and in the function, we just <code>jmp</code> to that location (register) and there is no '<code>ret</code>'
  so for executing this function in C, I just need to make a label for the function return address and load that label memory address into the <code>'rdx'</code> and jmp to that assembly function, and then it's done so I designed this code</p>
  <pre><code>unsigned
  calling_asm_func() {
      unsigned res;
      __asm__ __volatile__(&quot;jmp\tmy_asm_func&quot; : &quot;=a&quot; (res) : &quot;d&quot; (&amp;&amp; result) : &quot;rcx&quot;, &quot;rdi&quot;, &quot;rsi&quot;, &quot;r8&quot;, &quot;r9&quot;, &quot;r10&quot;, &quot;r11&quot;, &quot;memory&quot;);
      result:
      return res;
  }
  </code></pre>
  <p>it looks fine and it's ok but the generated assembly code is wrong !!!!!!!!</p>
  <pre><code>calling_asm_func:
  .L2:
    mov edx, OFFSET FLAT:.L2
    jmp my_asm_func
    ret
  </code></pre>
  <p>.L2 Must be above of <code>ret</code> as you can see it in the C code
  what is the problem? How can I fix it?</p>
  <p>It must be something like this:</p>
  <pre><code>calling_asm_func:
    mov edx, OFFSET FLAT:.L2
    jmpmy_asm_func
  .L2:
    ret
  </code></pre>
  <p>See this on <a href="https://godbolt.org/z/ar7xe5" rel="nofollow noreferrer">GodBolt</a> with GCC 10.2</p>
  <p><strong>Also, it's funny ! With -O1 option, it's OK and there is no problem !!!!!!! But the problem is with -O2 and -O3 !!!</strong></p>