Assign string to dereference of register inline

Viewed 74

I have an $rsi that is currently a pointer to a string and I'd like to change the value of that string using C in-line assembly.

The code I have now is:

char *my_str = "abc123";
asm("mov %[changed_string], %%rsi\n" :: [changed_string] "r" (my_str));

This is obviously loading the VALUE of my_str into $rsi. I know this translates to assembly as:

mov rsi, my_str

and if I were to examine the value of $rsi it would be my_str, effectively overwriting the pointer, which is not what I want to do.

I know in assembly I can accomplish what I want by adding brackets around $rsi:

mov [rsi], my_str

But when I do that in C I'm met with an error:

asm("mov %[changed_string], %%[rsi]\n" :: [changed_string] "r" (my_str));

Error: bad register name: %[rsi]
0 Answers
Related