Skip to content

Commit 8a3ff5a

Browse files
committed
Add library arrayalloc.asm
This library allocates arrays (initialized or not). Uninitalized arrays are filled with zeros. Initialized ones, are copied (LDIR) from a constant zone. This form of arrays are used for local (within a function body) declared ones.
1 parent 14997f5 commit 8a3ff5a

1 file changed

Lines changed: 63 additions & 0 deletions

File tree

library-asm/arrayalloc.asm

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
2+
#include once <calloc.asm>
3+
4+
5+
; ---------------------------------------------------------------------
6+
; __ALLOC_LOCAL_ARRAY
7+
; Allocates an array element area in the heap, and clears it filling it
8+
; with 0 bytes
9+
;
10+
; Parameters
11+
; HL = Offset to be added to IX => HL = IX + HL
12+
; BC = Length of the element area = n.elements * size(element)
13+
; DE = PTR to the index table
14+
;
15+
; Returns:
16+
; HL = (IX + HL) + 4
17+
; ---------------------------------------------------------------------
18+
19+
__ALLOC_LOCAL_ARRAY:
20+
push de
21+
push ix
22+
pop de
23+
add hl, de ; hl = ix + hl
24+
pop de
25+
ld (hl), e
26+
inc hl
27+
ld (hl), d
28+
inc hl
29+
push hl
30+
call __MEM_CALLOC
31+
pop de
32+
ex de, hl
33+
ld (hl), e
34+
inc hl
35+
ld (hl), d
36+
ret
37+
38+
39+
; ---------------------------------------------------------------------
40+
; __ALLOC_INITIALIZED_LOCAL_ARRAY
41+
; Allocates an array element area in the heap, and clears it filling it
42+
; with 0 bytes
43+
;
44+
; Parameters
45+
; HL = Offset to be added to IX => HL = IX + HL
46+
; BC = Length of the element area = n.elements * size(element)
47+
; DE = PTR to the index table
48+
; TOP of the stack = PTR to the element area
49+
; Returns:
50+
; Nothing
51+
; ---------------------------------------------------------------------
52+
53+
__ALLOC_INITIALIZED_LOCAL_ARRAY:
54+
push bc
55+
call __ALLOC_LOCAL_ARRAY
56+
pop bc
57+
pop hl
58+
ex (sp), hl
59+
; HL = data table
60+
; BC = length
61+
; DE = new data area
62+
ldir
63+
ret

0 commit comments

Comments
 (0)