summaryrefslogtreecommitdiff
path: root/tests/fixtures/stack.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/stack.s
parentd130fe27fa753be02ed76fd9b277aa3c3d928eb9 (diff)
downloadlibmcpu-0.4.0.tar.xz
Version 0.4.00.4.0
Diffstat (limited to 'tests/fixtures/stack.s')
-rw-r--r--tests/fixtures/stack.s32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/fixtures/stack.s b/tests/fixtures/stack.s
new file mode 100644
index 0000000..9b45785
--- /dev/null
+++ b/tests/fixtures/stack.s
@@ -0,0 +1,32 @@
+; STACK instruction example.
+;
+; Build/run from examples/:
+; ../utils/mcpu-as -o stack.o stack.s
+; ../utils/mcpu-ld --stack-size=128 -o stack stack.o
+; ../utils/mcpu-run --int-reg=r64@0x00028 stack
+;
+; Expected output: 22
+;
+.text
+_start_life:
+ LDI r64@0x00000, 11
+ LDI r64@0x00008, 22
+
+ ; STACK grows downward. cpu-run initializes SP to stack_size.
+ PUSH r64@0x00000
+ PUSH r64@0x00008
+
+ ; Current stack top contains 22, SP+8 contains 11.
+ LDSP r64@0x00010, 8
+ STSP 0, r64@0x00000
+
+ POP r64@0x00018
+ POP r64@0x00020
+
+ ; Reserve a 16-byte local frame without automatic padding.
+ ADJSP -16
+ STSP 0, r64@0x00008
+ LDSP r64@0x00028, 0
+ ADJSP 16
+
+ HALT