1 
2 #include <stdio.h>
3 
4 typedef  unsigned int  UInt;
5 
test_jcxz(UInt arg)6 UInt 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 
test_jecxz(UInt arg)27 UInt 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 
main(void)48 int 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