1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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
|