added basic allocator

This commit is contained in:
2025-07-07 20:39:13 +02:00
parent c1a55fa3ff
commit 51ffd98872
6 changed files with 93 additions and 15 deletions
+23
View File
@@ -0,0 +1,23 @@
%include "symbols.asm"
section .bss
brk_pointer: RESQ 1
section .text
global init_alloc
init_alloc:; initialize allocator, optionaly return brk pointer in rax
mov rax, SYS_BRK
mov rdi, 0
syscall
mov [brk_pointer], rax
ret
global alloc
alloc:; Takes lenght of data in rdi and returns pointer in rax
mov rax, SYS_BRK
mov rcx, [brk_pointer]
push rcx
syscall; size already in rdi
mov [brk_pointer], rax
pop rax
ret
+45 -8
View File
@@ -1,19 +1,56 @@
SYS_EXIT equ 60
SYS_IOCTL equ 16
STDOUT equ 1
TIOCGWINSZ equ 0x5413
%include "symbols.asm"
section .bss
multipurpuse_buf: RESB 8
str_buf: resb 4
term_rows: RESW 1
term_cols: RESW 1
section .data
section .text
global _start
extern print_str
extern unsigned_int_to_ascii
extern init_alloc
extern alloc
global _start
_start:
; get terminal dimensions
mov rax, SYS_IOCTL
mov rdi, STDOUT
mov rsi, TIOCGWINSZ
lea rdx, [multipurpuse_buf]
syscall
mov word ax, [multipurpuse_buf]; rows are stored at offset 0
mov [term_rows], ax
mov word ax, [multipurpuse_buf+2]; cols are stored at offset 2
mov [term_cols], ax
; handle args
pop rcx; get argc (number of arguments)
cmp rcx, 1
jle .no_arguments_provided
; TODO hanndle arguments
.no_arguments_provided:
call init_alloc
mov ax, [term_rows]
dec ax; one less than terminal size for statusbar
mov cx, [term_cols]
mul rcx
mov rdi, rax
call alloc
mov r15, rax; stores pointer to gameboard array
mov rax, SYS_EXIT
mov rdi, 0 ; return code
syscall
+1 -3
View File
@@ -1,6 +1,4 @@
SYS_WRITE equ 1
STDOUT equ 1
ASCII_ZERO equ 48
%include "symbols.asm"
section .text
+9
View File
@@ -0,0 +1,9 @@
SYS_EXIT equ 60
SYS_IOCTL equ 16
SYS_WRITE equ 1
SYS_BRK equ 12
STDOUT equ 1
TIOCGWINSZ equ 0x5413
ASCII_ZERO equ 48