Home | History | Annotate | Download | only in x86
      1 #include "tests/asm.h"
      2 #include <stdio.h>
      3 
      4 int arg = 0;
      5 int res = 0;
      6 
      7 extern void loop_plain ( void );
      8 asm("\n"
      9 ".text\n"
     10 VG_SYM(loop_plain) ":\n"
     11 "\tpushl %ecx\n"
     12 "\tmovl $999, %eax\n"
     13 "\tmovl " VG_SYM(arg) ", %ecx\n"
     14 
     15 "0:\n"
     16 "\tdecl %eax\n"
     17 "\tdecl %eax\n"
     18 "\tdecl %eax\n"
     19 "\tloop 0b\n"
     20 
     21 "\tmovl %eax, " VG_SYM(res) "\n"
     22 "\tpopl %ecx\n"
     23 "\tret\n"
     24 );
     25 
     26 extern void loop_ne ( void );
     27 asm("\n"
     28 ".text\n"
     29 VG_SYM(loop_ne) ":\n"
     30 "\tpushl %ecx\n"
     31 "\tmovl $999, %eax\n"
     32 "\tmovl " VG_SYM(arg) ", %ecx\n"
     33 
     34 "0:\n"
     35 "\tdecl %eax\n"
     36 "\tdecl %eax\n"
     37 "\tdecl %eax\n"
     38 "\tloopne 0b\n"
     39 
     40 "\tmovl %eax, " VG_SYM(res) "\n"
     41 "\tpopl %ecx\n"
     42 "\tret\n"
     43 );
     44 
     45 extern void loop_e ( void );
     46 asm("\n"
     47 ".text\n"
     48 VG_SYM(loop_e) ":\n"
     49 "\tpushl %ecx\n"
     50 "\tmovl $999, %eax\n"
     51 "\tmovl " VG_SYM(arg) ", %ecx\n"
     52 
     53 "0:\n"
     54 "\tdecl %eax\n"
     55 "\tdecl %eax\n"
     56 "\tdecl %eax\n"
     57 /* invert the Z flag */
     58 "\tpushfl\n"
     59 "\txorl $64, 0(%esp)\n"
     60 "\tpopfl\n"
     61 "\tloope 0b\n"
     62 
     63 "\tmovl %eax, " VG_SYM(res) "\n"
     64 "\tpopl %ecx\n"
     65 "\tret\n"
     66 );
     67 
     68 int main ( void )
     69 {
     70    res = 0; arg = 10;  loop_plain(); printf("res = %d\n", res);
     71 
     72    res = 0; arg = 10;  loop_ne();    printf("res = %d\n", res);
     73    res = 0; arg = 500; loop_ne();    printf("res = %d\n", res);
     74 
     75    res = 0; arg = 10;  loop_e();    printf("res = %d\n", res);
     76    res = 0; arg = 500; loop_e();    printf("res = %d\n", res);
     77 
     78    return 0;
     79 }
     80