home *** CD-ROM | disk | FTP | other *** search
/ BURKS 2 / BURKS_AUG97.ISO / BURKS / SOFTWARE / LIBS / PMC101.ZIP / LIBSRC.ZIP / BMCORELE.ASM (.txt) < prev    next >
Assembly Source File  |  1994-06-24  |  3KB  |  99 lines

  1. ;──────────────────────────────────────────────────────────────────────────────
  2. ;                          MEMBLOCK Memory Core Left
  3. ;──────────────────────────────────────────────────────────────────────────────
  4. ; Borland C++ 4.0 for WIN32 prototype:
  5. ; DWORD __pascal mbcoreleft (MEMBLOCK *mb);
  6. ;
  7. ; Returns: OK   - Largest free memory block (can be 0)
  8. ;          Fail - NULL
  9. ;
  10. ; version 0.3
  11. ; - White Shadow -
  12. ;
  13. .386p
  14. Ideal
  15. include "bmmalloc.inc"
  16.  
  17. Public MBCORELEFT
  18.  
  19.  
  20. ;──────────────────────────────────────────────────────────────────────────────
  21. Segment _TEXT byte public use32 'CODE'
  22. Assume  cs:_TEXT, ds:DGROUP
  23.  
  24. ; -- argument stack offsets
  25. arg1 = 0                ; -> MEMBLOCK
  26.  
  27. MBCORELEFT:     push ebx
  28. pct = (4)+(1*4)
  29.                 ;-- Load MEMBLOCK info
  30.                 mov  eax, [esp+pct+arg1]        ; -> MEMBLOCK
  31.                 mov  ebx, [eax+MEMBLOCK.base]   ; linear adx of MEMBLOCK
  32.                 sub  ebx, [_database]           ; relative ofs to DGROUP
  33.                 mov  edx, [eax+MEMBLOCK.size]
  34.                 add  edx, ebx                   ; -> end of MEMBLOCK + 1
  35.  
  36.                 ;-- MEMBLOCK uninitalized?
  37.                 cmp  edx, ebx
  38.                 je   ExitNull
  39.  
  40. If DebugMode    ;-- Check MBSig
  41.                 cmp  [dword ebx], MBSig
  42.                 jne  ExitNull                   ; quere rout, just exit
  43.                 add  ebx, MBSigSize             ; -> first node
  44. EndIf
  45.                 ;-- Set greatest MemArea
  46.                 xor  ecx, ecx
  47.  
  48. ;---------------
  49.  
  50. SearchLoop:
  51. ; ebx -> MemNode to check
  52. ; ecx - Largest MemArea (so far)
  53. ; edx -> final byte of MEMBLOCK + 1
  54.  
  55.                 ;-- Get node data
  56.                 mov  eax, [ebx+MemNode.size]
  57.  
  58. If DebugMode    ;-- Check Node Integrity
  59.                 xor  eax, NodeSigKey
  60.                 cmp  [ebx+MemNode.sig], eax
  61.                 jne  ExitNull
  62.                 xor  eax, NodeSigKey
  63. EndIf
  64.                 ;-- Node Free?
  65.                 test eax, 80000000h
  66.                 jnz  NextNode
  67.  
  68.                 ;-- Size found > largest so far?
  69.                 cmp  ecx, eax
  70.                 ja   NextNode
  71.                 mov  ecx, eax                   ; Store >
  72.  
  73. NextNode:       ;-- Point to next MemNode
  74.                 and  eax, 7fffffffh
  75.                 add  ebx, size MemNode
  76.                 add  ebx, eax
  77.  
  78.                 cmp  ebx, edx
  79.                 jb   SearchLoop
  80.                 ja   ExitNull
  81.  
  82. ;---------------
  83.  
  84. Exit:
  85. ; ecx - Largest MemArea
  86.                 mov  eax, ecx
  87.                 pop  ebx
  88.                 ret  4                          ; 1 arg
  89.  
  90. ;---------------
  91.  
  92. ExitNull:       xor  ecx, ecx                   ; return null on error
  93.                 jmp  short Exit
  94.  
  95.  
  96. ;──────────────────────────────────────────────────────────────────────────────
  97. EndS            _TEXT
  98. End
  99.