home *** CD-ROM | disk | FTP | other *** search
/ Groovy Bytes: Behind the Moon / groovybytes.iso / GROOVY / SND_TOOL / FUNK108A.ZIP / DOS32V30.ZIP / PAL / MALLOC / MAXAVAIL.ASM < prev    next >
Encoding:
Assembly Source File  |  1995-05-20  |  1.8 KB  |  54 lines

  1. ;****************************************************************************
  2. ; Filename: MAXAVAIL.ASM
  3. ;   Author: Peter Andersson
  4. ;  Version: 0.0
  5. ;  Created: 1994.12.25
  6. ;  Updated: -
  7. ;****************************************************************************
  8. ; Copyright Peter Andersson, 1994-1995.
  9. ; All rights reserved.
  10. ;****************************************************************************
  11. ; Function: ULONG maxavail(VOID);
  12. ;    Input: nothing
  13. ;   Output: largest free block on the heap.
  14. ;  Comment: PALmaxavail returns the size of the largest free block on the heap.
  15. ;           OBSERVE: This has nothing to do with how much memory your system
  16. ;           has available.
  17. ;****************************************************************************
  18.  
  19.     Include    STDDEF.INC
  20.     Include    "MEMORY.INC"
  21.  
  22.     Codeseg
  23.  
  24. Proc    maxavail
  25.         Mov    Edx,Offset BlockTableEnd-Size FreeBlock            ; Get the last block list pointer
  26.         Clear    Eax                            ; Clear the largest available variable
  27.         Push    Ebx
  28.     Align    4
  29. @@Loop01:    Mov    Ebx,[Edx+FreeBlock.NextFree]                ; Get next available FreeBlock
  30.     Align    4
  31. @@Loop02:    Mov    Ecx,[Ebx+FreeBlock.BlockSize]                ; Get the block size
  32.         Jecxz    @@Next01                        ; If it's zero, exit
  33.         Cmp    Eax,Ecx                            ; Compare the size
  34.         Mov    Ebx,[Ebx+FreeBlock.NextFree]                ; Get the next memory block
  35.         Jae    @@Loop02
  36.         Mov    Eax,Ecx                            ; Get larger block size
  37.         Jmp    @@Loop02
  38.     Align    4
  39. @@Next01:    TestZ    Eax                            ; If it isn't zero then exit
  40.         Jnz    @@Exit01
  41.         Sub    Edx,Size FreeBlock                    ; Get next block size
  42.         Cmp    Edx,Offset BlockTable                    ; If it's above the first block then do another lap
  43.         Jae    @@Loop01
  44.         Pop    Ebx
  45.         Clear    Eax                            ; Return with no memory available (0)
  46.         Ret
  47.     Align    4
  48. @@Exit01:    Pop    Ebx
  49.         Sub    Eax,Size AllocBlock                    ; Return with the largest block available
  50.         Ret
  51. Endp
  52.  
  53.     End
  54.