summaryrefslogtreecommitdiff
path: root/tests/fixtures/indirect-control.s
diff options
context:
space:
mode:
authorkx <kx@radix-linux.su>2026-10-09 18:00:15 +0300
committerkx <kx@radix-linux.su>2026-10-09 18:00:15 +0300
commit065da3509019b15dd0e678072e6be629e5330bef (patch)
tree69c934c9e786ac048b4fbe8f4c4c5571661521f4 /tests/fixtures/indirect-control.s
parentd130fe27fa753be02ed76fd9b277aa3c3d928eb9 (diff)
downloadlibmcpu-0.4.0.tar.xz
Version 0.4.00.4.0
Diffstat (limited to 'tests/fixtures/indirect-control.s')
-rw-r--r--tests/fixtures/indirect-control.s39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/fixtures/indirect-control.s b/tests/fixtures/indirect-control.s
new file mode 100644
index 0000000..1e9d0e3
--- /dev/null
+++ b/tests/fixtures/indirect-control.s
@@ -0,0 +1,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