1

What do you need to keep in mind when using inline assembly mixed with C/C++? Do you always try to restore the registers to what they were prior to the assembly section before you leave it? I'm assuming the compiler doesn't save the current registers prior to the assembly section. Ex do you risk disrupting a variable if you haven't loaded to its memory location?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
FourierFlux
  • 439
  • 5
  • 13
  • 2
    Assuming you're using GCC-style syntax, you use Extended Asm `asm("code" : outputs : inputs : clobbers)` to tell the compiler which registers your asm steps on, as well as which registers are outputs or read-write in/out, and which are inputs. Also tell it about memory operands so it knows what C objects might have changed. See https://stackoverflow.com/tags/inline-assembly/info for guides / docs. – Peter Cordes Feb 02 '22 at 05:17

0 Answers0