fa/low-level-examples/dynamic_alloc_brk.fa
Ari Archer de936a7513
Unsized strings, pop keyword and dead code elimination
Signed-off-by: Ari Archer <ari.web.xyz@gmail.com>
2022-07-22 10:43:57 +03:00

23 lines
776 B
Text

include 'std/std.fa'
macro SIZE 256 end
macro SYS_brk 12 end
macro main
0 %SYS_brk sys 2 -- Get the current .data addr
%SIZE add -- Add SIZE to data
%SYS_brk sys 2 -- Expand .data
copy -- Copy new .data addr
%SIZE swap --< You need to swap because SYS_read
the buffer in a different order >--
%STDIN %SYS_read sys 4 -- Perform a read from STDIN
swap %puts -- Output the buffer
0 %SYS_brk sys 2 --< Get the current .data (could
use `copy` but I'm lazy >--
%SIZE swap sub %SYS_brk sys 2 pop -- Set .data to its initial size
%EXIT_SUCCESS %exit
end
%main