Copy contents of variable C to register (GCC)

Since I am very new to GCC I am having a problem with inline assembly code. The problem is that I cannot figure out how to copy the contents of a C variable (which is of type UINT32

) into a register eax

. I have tried the below code:

__asm__
(
    // If the LSB of src is a 0, use ~src.  Otherwise, use src.
    "mov     $src1, %eax;"
    "and     $1,%eax;"
    "dec     %eax;"
    "xor     $src2,%eax;"

    // Find the number of zeros before the most significant one.
    "mov     $0x3F,%ecx;"
    "bsr     %eax, %eax;"
    "cmove   %ecx, %eax;"
    "xor     $0x1F,%eax;"
);

      

However mov $src1, %eax;

does not work.

Can anyone suggest a solution?

+3


source to share


1 answer


I am assuming you are looking for an advanced assembly , for example:

    int a=10, b;
    asm ("movl %1, %%eax;   /* eax = a */
          movl %%eax, %0;" /* b = eax */
         :"=r"(b)         /* output */
         :"r"(a)         /* input */
         :"%eax"        /* clobbered register */
         );        

      

In the above example, we made the value b

equal to value a

using the build and eax

register commands :

int a = 10, b;
b = a;

      



Please see the embedded comments.

Note:

mov $4, %eax          // AT&T notation

mov eax, 4            // Intel notation

      

Have a good read inline assembly in the GCC environment.

+11


source







All Articles