Files
damn_simple_architecture/resources/dsa/lib/memory/alloc.dsa
T
zxq5 3afeafc9d4 - compiler works for basic maths expressions and functions
- basic pointers and reading values from pointers works
- writing to pointers not yet implemented (looks painful so a problem
  for tomorrow)
- updated print library. the compiler has this hardcoded in all programs
  for now
2026-02-03 02:11:30 +00:00

38 lines
706 B
Plaintext

dw global_arena_start: 0x30000
dw global_arena_current: 0x30000
dw global_arena_end: 0x40000
arena_alloc:
// Just like bump allocator
push bpr
mov spr, bpr
ldw bpr, rg0, 8 // size argument
ldw global_arena_current, rg1
add rg1, rg0, rg2 // new_current = current + size
ldw global_arena_end, rg3
cmp rg2, rg3
jgt out_of_memory
stw rg2, global_arena_current
mov rg1, acc // return old current
stw acc, bpr, 8
mov bpr, spr
pop bpr
return
arena_reset:
// Reset to start
push bpr
mov spr, bpr
ldw global_arena_start, rg0
stw rg0, global_arena_current
mov bpr, spr
pop bpr
return