Support asm goto
[tinycc.git] / tests / tests2 / 127_asm_goto.c
blobde631aa326791f7f128839566e1d34acc2c95ec4
1 static int simple_jump(void)
3 asm goto ("jmp %l[label]" : : : : label);
4 return 0;
5 label:
6 return 1;
9 static int three_way_jump(int val, int *addr)
11 *addr = 42;
12 asm goto ("cmp $0, %1\n\t"
13 "jg %l[larger]\n\t"
14 "jl %l[smaller]\n\t"
15 "incl %0\n\t"
16 : "=m" (*addr)
17 : "r" (val)
19 : smaller, larger);
20 return 1;
21 smaller:
22 return 2;
23 larger:
24 return 3;
27 static int another_jump(void)
29 asm goto ("jmp %l[label]" : : : : label);
30 return 70;
31 /* Use the same label name as in simple_jump to check that
32 that doesn't confuse our C/ASM symbol tables */
33 label:
34 return 71;
37 extern int printf (const char *, ...);
38 int main(void)
40 int i;
41 if (simple_jump () == 1)
42 printf ("simple_jump: okay\n");
43 else
44 printf ("simple_jump: wrong\n");
45 if (another_jump () == 71)
46 printf ("another_jump: okay\n");
47 else
48 printf ("another_jump: wrong\n");
49 if (three_way_jump(0, &i) == 1 && i == 43)
50 printf ("three_way_jump(0): okay\n");
51 else
52 printf ("three_way_jump(0): wrong (i=%d)\n", i);
53 if (three_way_jump(1, &i) == 3 && i == 42)
54 printf ("three_way_jump(1): okay\n");
55 else
56 printf ("three_way_jump(1): wrong (i=%d)\n", i);
57 if (three_way_jump(-1, &i) == 2 && i == 42)
58 printf ("three_way_jump(-1): okay\n");
59 else
60 printf ("three_way_jump(-1): wrong (i=%d)\n", i);
61 return 0;