home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / cpm / asmutl / buffers.lbr / SALLOC.MZC / SALLOC.MAC
Encoding:
Text File  |  1987-01-15  |  1.3 KB  |  52 lines

  1. ;
  2. ; Allocate 16*a bytes on the stack, and leave a deallocate pointer
  3. ; on TOS.  Thus "pop h | sphl" will deallocate.  A maximum of 4096
  4. ; bytes can be allocated (a=0 means 256).  Remember to round up byte
  5. ; requirements to the next multiple of 16, or use sbcalloc entry.
  6. ; For more do the following in line:
  7. ;    mvi    a,0
  8. ;    call    salloc;        1st 4k
  9. ;    pop    h;        dealloc ptr, destroy hl
  10. ;    mvi    a,extra;    part from 4096 to 8192
  11. ;    call    salloc
  12. ;    xthl;            save dealloc to 1st part    
  13. ; At exit sp+2 is the lowest byte of the allocated memory.
  14. ; and carry is reset.
  15. ; a,f, (sp)
  16. .salloc::
  17.     push    b
  18.     push    d
  19.     push    h
  20.     ora    a;        check for 0=256*16=4096
  21.     cma
  22.     mov    l,a
  23.     mvi    h,0ffh
  24.     inx    h;        so 0 in results in ff00h
  25.     jnz    sallo1
  26.     dcr    h;        when we need a borrow
  27. sallo1:    dad    h
  28.     dad    h
  29.     dad    h
  30.     dad    h;        16* space requested
  31.     xchg
  32.     lxi    h,8;        allow for call & 3 pushes
  33.     dad    sp;        present sp
  34.     xchg
  35.     dad    d;        hl points to new stk top, de old
  36.     sphl;            adjust stack.
  37.     push    d;        save deallocate marker
  38.     xchg
  39.     mvi    b,4
  40. sallo2:    dcx    h;        copy ret adr. and saved regs to
  41.     mov    d,m;        new stack top area
  42.     dcx    h
  43.     mov    e,m
  44.     push    d
  45.     dcr    b
  46.     jnz    sallo2
  47.     pop    h
  48.     pop    d
  49.     pop    b
  50.     cmc;            carry was set from before
  51.     ret;            with sp pointing to dealloc byte
  52. φⁿ