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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
asm "extern malloc"
asm "extern realloc"
asm "extern free"
asm "extern printf"
{}uint8 _alert = "Alert!\n\0"
{}uint8 _dec = "%d\n\0"
/; _alloc (uint size) [~void]
~void out
# Mov size into proper register, and set all extras to zero
asm "mov rax, 0"
asm "mov rbx, 0"
asm "mov rcx, r8"
asm "mov rdx, 0"
asm "mov rdi, 0"
asm "mov rsi, 0"
asm "mov r8, 0"
asm "mov r9, 0"
asm "mov r10, 0"
asm "call malloc"
# Set out to the returned value
# (The compiler assignes spaces sequentially, and we have a uint in r8)
asm "mov r9, rax"
return out
;/
/; _realloc (~void ptr, uint new_size) [~void]
~void out
# Mov ptr and new size into proper registers, and set all extras to zero
asm "mov rax, 0"
asm "mov rbx, 0"
asm "mov rcx, r8"
asm "mov rdx, r9"
asm "mov rdi, 0"
asm "mov rsi, 0"
asm "mov r8, 0"
asm "mov r9, 0"
asm "mov r10, 0"
# Do call
asm "call realloc"
# Set out to the returned value
# (The compiler assignes spaces sequentially. We have a ptr in r8, and a uint in r9)
asm "mov r10, rax"
return out
;/
/; _delete (~void ptr)
# setup call by clearing most values
asm "mov rax, 0"
asm "mov rbx, 0"
asm "mov rcx, rax"
asm "mov rdx, 0"
asm "mov rdi, 0"
asm "mov rsi, 0"
asm "mov r8, 0"
asm "mov r9, 0"
asm "mov r10, 0"
# do call
asm "call free"
# there's no more to do 'cause free returns nothing
;/
/; _printf (~void str)
# setup call by clearing most values
asm "mov rcx, rax"
asm "mov rdx, 0"
asm "mov rdi, 0"
asm "mov rsi, 0"
asm "mov r8, 0"
asm "mov r9, 0"
asm "mov r10, 0"
# do call
asm "call printf"
# there's no more to do 'cause printf returns nothing
;/
/; _print_num (~void str, int num)
# setup call by clearing most values
asm "mov rcx, rax"
asm "mov rdx, rbx"
asm "mov rdi, 0"
asm "mov rsi, 0"
asm "mov r8, 0"
asm "mov r9, 0"
asm "mov r10, 0"
# do call
asm "call printf"
# there's no more to do 'cause printf returns nothing
;/
/; print_alert
_printf(~_alert{0})
;/
|