News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

inline assembly macros/expression symbols in g++

Started by bobl, January 08, 2010, 08:43:47 PM

Previous topic - Next topic

bobl

This is my first foray into inline asm in g++
I've worked out how to access variables defined in c, eg  "/dev/vcsa1" into eax in the example below.
Now I'd like to access a numerical expression defined in c (via #define).
My problem is I've seen no examples
If I can't access macros created with #define in c, then I'd be happy to use gas' ".equ"
and do it all in inline asm.

If anyone has ever done this....

Happy New Year!


#include <iostream>
using namespace std;
int main(){
   const char * device = "/dev/vcsa1";
   const char * recipient = "";

   //this is my preferred way of declaring "my_macro". I just don't know how to access it in inline asm.
   #define my_macro 3

   //This is how you use ".equ" in normal asm
   //This line compiles ok but I have no idea how you access "my_macro"
   //and all my attempts cause a segfault
   //__asm__ __volatile__(".equ my_macro,   3\n\t"); 

   //This is how you use variables defined in c. It works!
   __asm__ __volatile__(
      "movl  %%eax,%%ebx\n\t"
      :"=b"(recipient)
      :"a"(device), "b"(recipient)
      :
      );

   cout << recipient << "\n";
   return 0;
}


I managed to do it like this...


#include <iostream>
using namespace std;
int main(){
   const char * device = "/dev/vcsa1";
   int recipient = 0;

   __asm__ __volatile__(
      ".equ my_macro, 3\n\t"
      "movl $my_macro,%%ebx\n\t"
      :"=b"(recipient)
      :
      );

   cout << recipient << "\n";
   return 0;
}


but would still like to do it by accessing
#define my_macro 3
in c if possible