Home | History | Annotate | Download | only in amd64
      1 
      2 #include <stdio.h>
      3 
      4 typedef unsigned long long int ULong;
      5 
      6 extern ULong lahf_1 ( void );
      7 asm("\n"
      8 "lahf_1:\n"
      9 "\tpushq $0\n"
     10 "\tpopfq\n"
     11 "\tmovabsq $0xFFFFFFFFFFFFFFFF, %rax\n"
     12 "\tmovabsq $0x8765432112345678, %rdx\n"
     13 "\tsubq %rax, %rdx\n"
     14 "\t.byte 0x9F\n" /* lahf */
     15 "\tret\n"
     16 );
     17 
     18 extern ULong lahf_0 ( void );
     19 asm("\n"
     20 "lahf_0:\n"
     21 "\tpushq $0\n"
     22 "\tpopfq\n"
     23 "\tmovabsq $0x0, %rax\n"
     24 "\tmovabsq $0x8765432112345678, %rdx\n"
     25 "\tsubq %rax, %rdx\n"
     26 "\t.byte 0x9F\n" /* lahf */
     27 "\tret\n"
     28 );
     29 
     30 extern ULong sahf_then_lahf ( ULong );
     31 asm("\n"
     32 "sahf_then_lahf:\n"
     33 "\tmovq %rdi, %rax\n"
     34 "\t.byte 0x9E\n" /* sahf */
     35 "\tmovabsq $0, %rax\n"
     36 "\t.byte 0x9F\n" /* lahf */
     37 "\tret\n"
     38 );
     39 
     40 int main ( void )
     41 {
     42    ULong i;
     43    printf("0x%llx\n", lahf_0());
     44    printf("0x%llx\n", lahf_1());
     45    for (i = 0; i < 255; i++) {
     46       ULong x = sahf_then_lahf(i << 8);
     47       printf("%llx -> %llx\n", i, x);
     48    }
     49    return 0;
     50 }
     51