33 lines
478 B
NASM
33 lines
478 B
NASM
heap_size:
|
|
dw 0x0100
|
|
|
|
heap_init:
|
|
push ax ; byte value (0)
|
|
push cx ; loop counter
|
|
push di ; target ptr
|
|
push es
|
|
mov ax, ds
|
|
mov es, ax
|
|
xor ax, ax
|
|
mov cx, [heap_size]
|
|
mov di, heap
|
|
rep stosb ; rep makes this loop cx times, incrementing di, writing al
|
|
pop es
|
|
pop di
|
|
pop cx
|
|
pop ax
|
|
ret
|
|
|
|
; in ax number of bytes to alloc
|
|
; out ds:di
|
|
malloc:
|
|
push dx ; length of block index
|
|
or ax,0x0F
|
|
inc ax
|
|
mov dx, 0x100
|
|
mov bp, heap
|
|
|
|
int 0x2E
|
|
pop dx
|
|
ret
|