GCC embedded ASM with variable

I am trying to use the following ASM inline code in my C ++ source given for Visual Studio:

__asm { mov ecx,target } 

where target is a void * pointer. I do not know how to convert this to GCC-compatible code. I know that GCC uses synthax, for example:

 asm (".intel_syntax noprefix"); asm ("mov ecx,target"); 

but obviously there is a problem with the variable in this situation. So, can anyone explain to me how to use a pointer with embedded ASM using GCC for Windows?

Thank you for your help.

+6
source share
1 answer

try this assembly, this may help ... although it works for me.

 #include <stdlib.h> #include <stdio.h> int main(int argc, char *arg[]) { int retval; printf ( " retval = %d \n", retval ); asm volatile( "movl %%ecx , %0\n\t" :"=r" (retval)); printf ( "retval = %d \n", retval ); return 0; } 

displays the following value for me ... I tried debugging, the second value is the same as the value present in the ecx register.

p $ ecx

gdb command

 > retval = 0 > retval = -72537468 
+1
source

Source: https://habr.com/ru/post/980006/


All Articles