summaryrefslogtreecommitdiff
path: root/3/6_control/30_switch2.c
blob: 0c8cc85668449d2ae406be7483e084d534c33b67 (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
#include <stdio.h>

// x in %rdi
// switch2:
//   addq   $1, %rdi
//   cmpq   $8, %rdi
//   ja     .L2     if (x + 1) > 8 then goto default
//   jmp    *.L4(,%rdi,8)   take the address at x*8 from .L4
void switch2(long x, long *dest) {
    long val = 0;
    switch (x) {
        case -1:
            printf(".L9");
            break;
        case 0:
        case 7:
            printf(".L5");
            break;
        case 1:
            printf(".L6");
            break;
        case 2:
        case 4:
            printf(".L7");
            break;
        case 5:
            printf(".L8");
            break;

    }
    *dest = val;
}

int main(void) {
    printf("val: %ld\n");
    return 0;
}