aboutsummaryrefslogtreecommitdiff
path: root/tinycc/tests/tests2/127_asm_goto.c
blob: de631aa326791f7f128839566e1d34acc2c95ec4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
static int simple_jump(void)
{
  asm goto ("jmp %l[label]" : : : : label);
  return 0;
label:
  return 1;
}

static int three_way_jump(int val, int *addr)
{
  *addr = 42;
  asm goto ("cmp $0, %1\n\t"
            "jg %l[larger]\n\t"
            "jl %l[smaller]\n\t"
            "incl %0\n\t"
            : "=m" (*addr)
            : "r" (val)
            :
            : smaller, larger);
  return 1;
smaller:
  return 2;
larger:
  return 3;
}

static int another_jump(void)
{
  asm goto ("jmp %l[label]" : : : : label);
  return 70;
  /* Use the same label name as in simple_jump to check that
     that doesn't confuse our C/ASM symbol tables */
label:
  return 71;
}

extern int printf (const char *, ...);
int main(void)
{
  int i;
  if (simple_jump () == 1)
    printf ("simple_jump: okay\n");
  else
    printf ("simple_jump: wrong\n");
  if (another_jump () == 71)
    printf ("another_jump: okay\n");
  else
    printf ("another_jump: wrong\n");
  if (three_way_jump(0, &i) == 1 && i == 43)
    printf ("three_way_jump(0): okay\n");
  else
    printf ("three_way_jump(0): wrong (i=%d)\n", i);
  if (three_way_jump(1, &i) == 3 && i == 42)
    printf ("three_way_jump(1): okay\n");
  else
    printf ("three_way_jump(1): wrong (i=%d)\n", i);
  if (three_way_jump(-1, &i) == 2 && i == 42)
    printf ("three_way_jump(-1): okay\n");
  else
    printf ("three_way_jump(-1): wrong (i=%d)\n", i);
  return 0;
}