I want to access local variable declared in C in inline arm Assembly. How do I do that?
Global variables can be accessed like this,
int temp = 0;
Fun
According to GCC docs: 6.45.2.3 Output Operands
You can pass the values like this:
#include
int main(int argc, char *argv[]) {
int src = 1;
int dst;
asm ("mov %1, %0\n\t add $1, %0" : "=r" (dst) : "r" (src));
printf("0x%X\n", dst);
return 0;
}
After your asm code you put the ':'
character and the values you want to pass like this: "(=|+)(r|m)" (variable)
. Use '='
when overriding the value and '+'
when reading or overriding the value, then use the 'r'
letter if the value resides in a register or 'm'
if it resides in memory.