summaryrefslogtreecommitdiff
path: root/tests/fixtures/call.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/call.s
parentd130fe27fa753be02ed76fd9b277aa3c3d928eb9 (diff)
downloadlibmcpu-0.4.0.tar.xz
Version 0.4.00.4.0
Diffstat (limited to 'tests/fixtures/call.s')
-rw-r--r--tests/fixtures/call.s39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/fixtures/call.s b/tests/fixtures/call.s
new file mode 100644
index 0000000..bfc9965
--- /dev/null
+++ b/tests/fixtures/call.s
@@ -0,0 +1,39 @@
+; Build/run from examples/:
+; ../utils/mcpu-as -o call.o call.s
+; ../utils/mcpu-ld --stack-size=128 -o call call.o
+; ../utils/mcpu-run --int-reg=r64@0x00010 call
+;
+; Expected output: 33
+;
+; LibCPU CALL ABI example.
+;
+; add2(a,b): this two-r64 argument block is exactly 16 bytes, so the
+; traditional right-to-left PUSH sequence also satisfies the formal ABI.
+; CALL then pushes
+; the 64-bit return PC, therefore on callee entry:
+; SP+0 = return address
+; SP+8 = first argument a
+; SP+16 = second argument b
+;
+; Before CALL, SP is 16-byte aligned. The r64 result is returned in the canonical ABI return view
+; r64@0x7fff8. The caller removes its own arguments with ADJSP.
+
+.text
+_start_life:
+
+ LDI r64@0x00000, 11
+ LDI r64@0x00008, 22
+
+ PUSH r64@0x00008 ; second/rightmost argument b
+ PUSH r64@0x00000 ; first/leftmost argument a
+ CALL add2
+ ADJSP 16 ; caller cleanup
+
+ MOV r64@0x00010, r64@0x7fff8
+ HALT
+
+add2:
+ LDSP r64@0x00100, 8 ; a
+ LDSP r64@0x00108, 16 ; b
+ IADD r64@0x7fff8, r64@0x00100, r64@0x00108
+ RET