Quantcast
Viewing all articles
Browse latest Browse all 2

Answer by Chris for How to use a variable offset in inline assembly?

That's not possible using the instruction with a constant offset. To generate the code, the offset would need to be known at compile time, and not be variable. You have to use a different instruction, an indirect load with base register and offset:

int foo(int64_t offset, double value){    asm volatile ("movsd %0, (%%rsp,%1)" :: "x" (value), "r" (offset)        : "memory"    );}

You could also let the CPU do the multiplication by 8 by using a scaled offset addressing mode:

int foo(int64_t offset, double value){    asm volatile ("movsd %0, (%%rsp,%1,8)" :: "x" (value), "r" (offset)        : "memory"    );}

Or if you want to emulate push, then sub $8, %%rsp / movsd %0, (%%rsp), but you can't mess with the stack pointer from inline asm without breaking compiler-generated code.


Viewing all articles
Browse latest Browse all 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>