summaryrefslogtreecommitdiff
path: root/tests/fixtures/indirect-control.s
blob: 1e9d0e322b51b10d7557ce3af5cade4d73e2dadf (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
; Indirect CALLP/JMPP control-flow example.
;
; Build/run from examples/:
;   ../utils/mcpu-as -o indirect-control.o indirect-control.s
;   ../utils/mcpu-ld --stack-size=512 -o indirect-control indirect-control.o
;   ../utils/mcpu-run --int-reg=r64@0x00020 indirect-control
;
; Expected output: 42
;
.data

.align 8
dispatch:
        .cptr indirect_function
        .cptr done

.text
_start_life:

        ; Load a PROGRAM PTR64 from DATA and call through it.
        LEA     r64@0x00000, dispatch
        LOADP   r64@0x00008, r64@0x00000
        CALLP   r64@0x00008

        ; Select the second entry and jump through it.
        PADDI   r64@0x00000, r64@0x00000, 8
        LOADP   r64@0x00010, r64@0x00000
        JMPP    r64@0x00010

        ; JMPP must skip this path.
        LDI     r64@0x00020, 99
        HALT

indirect_function:
        LDI     r64@0x00020, 42
        RET

done:
        HALT