summaryrefslogtreecommitdiff
path: root/tests/fixtures/stack.s
diff options
context:
space:
mode:
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