I was writing inline assembly code for an operating system assignment. I have some questions regarding inline assembly and its translation into machine code by the gcc compiler.
- asm binds input and output to registers. Do we need to save all the registers before doing any operation using asm and restore them back after the operation? Because if the bound register happens to be a register containing an important value in the program, that might be lost and the program might not behave in an expected manner.
- How is it decided which register will be bound to which input?
- Does asm save the registers used for input and output and restore them on its own?
Edit: Example code is as follows. Which register is top bound to?
unsigned long long top;
asm volatile("mov %0, %%rsp;"
:
:"r"(top)
:"memory");