Home | History | Annotate | Download | only in amd64
      1 #include <stdio.h>
      2 #include <stdlib.h>
      3 typedef unsigned long long int ULong;
      4 
      5 ULong data;
      6 ULong result;
      7 
      8 
      9 extern void shrl32_with_0x10 ( void );
     10 asm("\n"
     11 "shrl32_with_0x10:\n"
     12 "\tpushq %rdx\n"
     13 "\tmovq data, %rdx\n"
     14 "\tshr $0x10, %edx\n"
     15 "\tjne shrl32_with_0x10_jump\n"
     16 "\tshrl32_with_0x10_cont:\n"
     17 "\tmovq %rdx, result\n"
     18 "\tpopq %rdx\n"
     19 "\tret\n"
     20 "\tshrl32_with_0x10_jump:\n"
     21 "\tmov $0xdeaddead, %edx\n"
     22 "\tjmp shrl32_with_0x10_cont\n"
     23 );
     24 
     25 
     26 int main ( void )
     27 {
     28   char *p;
     29 
     30   printf("\nshrl 0x10 with unitialised bits\n");
     31   ULong *notinitialised = malloc(sizeof(ULong)); // Not initialised data.
     32   data = *notinitialised;
     33   p = (char*) &data;
     34   p[0] = 0x11;
     35   // p[1] = 0x22;
     36   p[2] = 0x33;
     37   p[3] = 0x44;
     38 
     39   shrl32_with_0x10();
     40 
     41   printf("non zero jump on p[2..3] 0x%016llx\n", result);
     42 
     43   data = *notinitialised;
     44   p = (char*) &data;
     45   p[0] = 0x00;
     46   // p[1] = 0x00;
     47   p[2] = 0x00;
     48   p[3] = 0x00;
     49 
     50   shrl32_with_0x10();
     51 
     52   printf("zero jump on p[2..3] 0x%016llx\n", result);
     53   return 0;
     54 }
     55