7

I'm 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 don't know how to convert this into GCC-compatible code. I know that GCC use synthax like :

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

but obviously there's a problem with the variable in this situation. So, anyone could explain me how to use a pointer with inline ASM using GCC for Windows ?

Thanks for your help.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
MadMass
  • 313
  • 3
  • 10
  • 3
    Try to read this, here are some useful examples: http://www.ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html#s7 – strannik Dec 21 '14 at 17:06
  • this is useful: http://asm.sourceforge.net/articles/rmiyagi-inline-asm.txt – gj13 Dec 21 '14 at 18:50
  • Also [this link](http://www.ethernut.de/en/documents/arm-inline-asm.html). GCC inline assembler is difficult! But for your simple case, I'm sure you will find a usable example among these three links. – TonyK Dec 21 '14 at 22:28
  • 2
    3 links and no one mentions the official gcc docs for asm (https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html)? It's long and more detailed than a beginner might want, but it is the official source for gcc info, and pretty much everything you'd ever want to know is there. – David Wohlferd Dec 21 '14 at 22:37

1 Answers1

1

try this assembly this might help.... atleast it is working 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; 
}

prints the following value for me ... I have tried it debugging the second value is same as the value present in ecx register.

p $ecx

command in gdb

> retval = 0  
> retval = -72537468
theadnangondal
  • 1,546
  • 3
  • 14
  • 28