-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhello.af
More file actions
32 lines (26 loc) · 909 Bytes
/
Copy pathhello.af
File metadata and controls
32 lines (26 loc) · 909 Bytes
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
use' lang.af
" hello world! (using libc IO)" .log .lf
\ Don't have to use libc for IO. Just call the kernel.
\
\ x8 = 64 -> Linux write syscall.
\ x16 = 4 -> XNU write syscall.
\
\ Inspired by Cosmopolitan Libc: https://justine.lol/cosmopolitan.
fun: sys_write { _fdes _str _len } [
0 .comp_realloc_reg \ x0 clobber = kernel return value.
8 .comp_realloc_reg \ x8 clobber = Linux sysno.
8 64 .asm_mov_imm .comp_instr \ mov x8, 64
16 4 .asm_mov_imm .comp_instr \ mov x16, 4
asm_svc .comp_instr \ svc 666
] end
.flush
STDOUT s" hello world! (using syscall)" .sys_write
STDOUT CRLF 2 .sys_write
fun: bool_str { val -- str } if val .then " true" else " false" end end
" bool_str(false): " .log false .bool_str .log .lf
" bool_str(true): " .log true .bool_str .log .lf
char' @ .logc
char' A .logc
char' B .logc
char' C .logc
.lf \ @ABC