summaryrefslogtreecommitdiff
path: root/tests/fixtures/block-copy.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/block-copy.s
parentd130fe27fa753be02ed76fd9b277aa3c3d928eb9 (diff)
downloadlibmcpu-0.4.0.tar.xz
Version 0.4.00.4.0
Diffstat (limited to 'tests/fixtures/block-copy.s')
-rw-r--r--tests/fixtures/block-copy.s46
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/fixtures/block-copy.s b/tests/fixtures/block-copy.s
new file mode 100644
index 0000000..81422e2
--- /dev/null
+++ b/tests/fixtures/block-copy.s
@@ -0,0 +1,46 @@
+; Build/run from examples/:
+; ../utils/mcpu-as -o block-copy.o block-copy.s
+; ../utils/mcpu-ld --stack-size=512 -o block-copy block-copy.o
+; ../utils/mcpu-run --int-reg=r64@0x00028 block-copy
+;
+; Expected output: 22
+;
+; LibCPU block-copy example.
+;
+; 1. Copy a 32-byte object from DATA to a local STACK object with BMOVI.
+; 2. Use BMOV with a runtime byte count to perform an overlapping move
+; inside that STACK object. BMOV has memmove semantics.
+; 3. Read the moved value back through LOADP. Expected result: 22.
+
+.data
+.align 8
+source_object:
+ .integer 64, 11
+ .integer 64, 22
+ .integer 64, 33
+ .integer 64, 44
+
+.text
+_start_life:
+ ; Source PTR64 -> DATA object.
+ LEA r64@0x00000, source_object
+
+ ; Reserve 32 bytes for a local object and obtain its STACK PTR64.
+ ADJSP -32
+ LEASP r64@0x00008, 0
+
+ ; Fixed-size structure copy: DATA -> STACK.
+ BMOVI r64@0x00008, r64@0x00000, 32
+
+ ; Overlapping move inside the local object:
+ ; bytes [0..15] -> [8..23]. memmove semantics are required.
+ PADDI r64@0x00010, r64@0x00008, 8
+ LDI r64@0x00018, 16
+ BMOV r64@0x00010, r64@0x00008, r64@0x00018
+
+ ; The third 64-bit slot now contains the old second slot: 22.
+ PADDI r64@0x00020, r64@0x00008, 16
+ LOADP r64@0x00028, r64@0x00020
+
+ ADJSP 32
+ HALT