C
C
Centrix2019-07-14 13:49:25
C++ / C#
Centrix, 2019-07-14 13:49:25

How to access local variable from asm insert?

I am writing a program in C, and it so happened that assembler inserts are required (because the code is very small), the main problem is that from the asm insert I need to access a local variable, I tried to implement access to this variable through the frame pointer (rsp), but it didn't work for me. Here is an example of how I did it:

...
int a = 0;
asm("movq $5, (%rsp)\n");
...

I would be grateful for help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2019-07-14
@Centrix2132

asm("mov $5, %0" : "=r" (a));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question