Home | History | Annotate | Download | only in x86
      1 
      2 #include <assert.h>
      3 #include <stdio.h>
      4 #include <stdlib.h>
      5 
      6 unsigned int do32 ( unsigned int x )
      7 {
      8   unsigned int* y = malloc(sizeof(unsigned int));
      9   unsigned int* z = malloc(sizeof(unsigned int));
     10   unsigned int t;
     11   assert(y);
     12   assert(z);
     13   y[0] = x;
     14   __asm__ __volatile__(
     15      "pushl %0\n\t"
     16      "pushl %1\n\t"
     17      "popl %%ebx\n\t"
     18      "popl %%eax\n\t"
     19      "pushl 0(%%eax)\n\t"
     20      "popl 0(%%ebx)"
     21      : /*OUT*/
     22      : /*IN*/ "r"(y), "r"(z)
     23      : /*TRASH*/ "memory", "eax", "ebx"
     24   );
     25   t = z[0];
     26   free(y);
     27   free(z);
     28   return t;
     29 }
     30 
     31 unsigned short do16 ( unsigned short x )
     32 {
     33   unsigned short* y = malloc(sizeof(unsigned short));
     34   unsigned short* z = malloc(sizeof(unsigned short));
     35   unsigned short t;
     36   assert(y);
     37   assert(z);
     38   y[0] = x;
     39   __asm__ __volatile__(
     40      "pushl %0\n\t"
     41      "pushl %1\n\t"
     42      "popl %%ebx\n\t"
     43      "popl %%eax\n\t"
     44      "pushw 0(%%eax)\n\t"
     45      "popw 0(%%ebx)"
     46      : /*OUT*/
     47      : /*IN*/ "r"(y), "r"(z)
     48      : /*TRASH*/ "memory", "eax", "ebx"
     49   );
     50   t = z[0];
     51   free(y);
     52   free(z);
     53   return t;
     54 }
     55 
     56 
     57 int main ( void )
     58 {
     59    printf("do32: 0x%08X\n", do32(0xCafeBabe) );
     60    printf("do16: 0x%08X\n", (unsigned int)do16(0xfeBa) );
     61    return 0;
     62 }
     63