Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCC inline ASM with variable

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.

like image 215
MadMass Avatar asked Dec 21 '14 17:12

MadMass


1 Answers

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
like image 170
theadnangondal Avatar answered Oct 27 '22 01:10

theadnangondal