runtime/stdlib: add MaxAvail function
This commit is contained in:
parent
72b6ab6a30
commit
3fd6011e36
5 changed files with 75 additions and 24 deletions
|
|
@ -1792,6 +1792,38 @@ MAX_XT:
|
|||
FPADJ 4
|
||||
RET
|
||||
|
||||
; find largest free chunk on heap
|
||||
; args: none
|
||||
; returns: size of largest free chunk in bytes
|
||||
MAXAVAIL:
|
||||
FPADJ -4
|
||||
LOADC 0
|
||||
STORE 0 ; start with zero as result
|
||||
|
||||
LOADCP _HEAP_ANCHOR
|
||||
MXAV_L:
|
||||
DUP ; dup chunk ptr for later
|
||||
INC 4 ; move to size field
|
||||
LOADI ; load chunk size
|
||||
LOAD 0 ; compare with current result value
|
||||
CMPU.S0 LE ; compare with keeping first arg on stack
|
||||
CBRANCH MXAV_NEXT ; if smaller or equal, no change
|
||||
STORE 0 ; else store as new value
|
||||
BRANCH MXAV_NEXT2
|
||||
MXAV_NEXT:
|
||||
DROP
|
||||
MXAV_NEXT2:
|
||||
LOADI ; load next ptr
|
||||
DUP
|
||||
LOADCP _HEAP_ANCHOR ; compare with anchor
|
||||
CMPU NE
|
||||
CBRANCH MXAV_L ; if not equal, loop
|
||||
MXAV_XT:
|
||||
DROP ; drop chunk ptr
|
||||
LOAD 0 ; put result value on stack
|
||||
FPADJ 4
|
||||
RET
|
||||
|
||||
; check if a pointer is part of the free list
|
||||
; args: pointer returned by MEM_ALLOC
|
||||
; throws runtime error if the pointer is found
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue