home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / LANGUAGS / XLISP / XLISP11.ARK / SBRK.ASM < prev    next >
Assembly Source File  |  1986-10-12  |  2KB  |  95 lines

  1. ;
  2. ;    Rest of Full K&R alloc() and free() for AZTEC C II
  3. ;
  4. ;    This module copyright (c) 1982 William C. Colley III
  5. ;
  6. ; I grant Manx Software Systems permission to incorporate these functions
  7. ; into the AZTEC C library subject only to the condition that my copyright
  8. ; notice remain in the source code.  WCC3.
  9. ;
  10. ; See the module ALLOC.C for documentation.  To use this module, you must
  11. ; modify the AZTEC module CALLCPM.ASM by removing the definition of the
  12. ; location $MEMRY.  You also will save code if you remove their function
  13. ; xsettop()/xsbrk() as two of these functions will replace it.
  14. ;
  15.         PUBLIC    xsettop_, xsbrk_, rsvstk_, $MEMRY
  16.  
  17.         CSEG
  18.  
  19. ;******************************************************************************
  20.  
  21. xsettop_:    LXI    H, 4        ;Fudge up a call to xsbrk() to allocate
  22.         CALL    xsbrk1        ;  the space.
  23.  
  24.         INX    H        ;If xsbrk() returned -1, set the Z flag
  25.         MOV    A, H        ;  and return 0 as space was not
  26.         ORA    L        ;  available.
  27.         RZ
  28.  
  29.         DCX    H        ;If space was available, return a
  30.         RET            ;  pointer to the space.  Note that
  31.                     ;  Z flag is cleared at this point.
  32.  
  33. xsbrk_:        LXI    H, 2        ;Get size of block to allocate and
  34. xsbrk1:        DAD    SP        ;  compute end address of prospective
  35.         MOV    E, M        ;  block.
  36.         INX    H
  37.         MOV    D, M
  38.         LHLD    $MEMRY
  39.         DAD    D
  40.         XCHG
  41.  
  42.         JC    xsbrk2        ;If block wraps around top of memory,
  43.                     ;  not enough space available.
  44.  
  45.         LHLD    safety        ;Compute stack pointer less safety
  46.         DAD    SP        ;  margin -- i.e. top of memory.
  47.  
  48.         MOV    A, L        ;If end address > top of memory,
  49.         SUB    E        ;  not enough space available.
  50.         MOV    A, H
  51.         SBB    D
  52.         JC    xsbrk2
  53.  
  54.         LHLD    $MEMRY        ;If space is available, allocate
  55.         XCHG            ;  the space, set Z flag on pointer,
  56.         SHLD    $MEMRY        ;  and return pointer to space.
  57.         XCHG
  58.         MOV    A, H
  59.         ORA    L
  60.         RET
  61.  
  62. xsbrk2:        XRA    A        ;If not enough space, clear the Z flag
  63.         DCR    A        ;  and send back -1.
  64.         MOV    H, A
  65.         MOV    L, A
  66.         RET
  67.  
  68. ;******************************************************************************
  69.  
  70. rsvstk_:    LXI    H, 2        ;Get new stack safety margin.
  71.         DAD    SP
  72.         MOV    A, M
  73.         INX    H
  74.         MOV    H, M
  75.  
  76.         CMA            ;Negate and save it.
  77.         MOV    L, A
  78.         MOV    A, H
  79.         CMA
  80.         MOV    H, A
  81.         INX    H
  82.         SHLD    safety
  83.  
  84.         RET            ;Return nothing in particular.
  85.  
  86. ;******************************************************************************
  87.  
  88.         DSEG
  89.  
  90. safety:        DW    -1024        ;Default value of safety margin.
  91.  
  92.         END
  93. ***************************************************
  94.  
  95.