jcxz.c revision e739ac0589b4fb43561f801c4faba8c1b89f8680
1
2#include <stdio.h>
3
4typedef  unsigned int  UInt;
5
6UInt test_jcxz ( UInt arg )
7{
8   UInt block[2];
9   block[0] = arg;
10   block[1] = 0xdeadbeef;
11   __asm__ __volatile__(
12      "movl %0,%%ecx\n\t"
13      "movl $0,%%eax\n"
14      "0:\n\t"
15      "jcxz 1f\n\t"
16      "addl $1, %%eax\n\t"
17      "subl $1, %%ecx\n\t"
18      "jmp 0b\n"
19      "1:\n\t"
20      "movl %%eax, %1"
21      : /*out*/ : /*in*/ "m"(block[0]),
22                         "m"(block[1]) : /*trash*/ "eax","ecx","cc","memory"
23   );
24   return block[1];
25}
26
27UInt test_jecxz ( UInt arg )
28{
29   UInt block[2];
30   block[0] = arg;
31   block[1] = 0xdeadbeef;
32   __asm__ __volatile__(
33      "movl %0,%%ecx\n\t"
34      "movl $0,%%eax\n"
35      "0:\n\t"
36      "jecxz 1f\n\t"
37      "addl $1, %%eax\n\t"
38      "subl $1, %%ecx\n\t"
39      "jmp 0b\n"
40      "1:\n\t"
41      "movl %%eax, %1"
42      : /*out*/ : /*in*/ "m"(block[0]),
43                         "m"(block[1]) : /*trash*/ "eax","ecx","cc","memory"
44   );
45   return block[1];
46}
47
48int main ( void )
49{
50   UInt arg = 0x01028374;
51   printf("test_jcxz(0x%x)  = 0x%x\n", arg, test_jcxz(arg));
52   printf("test_jecxz(0x%x) = 0x%x\n", arg, test_jecxz(arg));
53   return 0;
54}
55