24. MEM_ALLOC

*------------------------------------------------------------------------------
* NAME          MEM_ALLOC
*------------------------------------------------------------------------------
* DEPENDENCY    None
* PURPOSE       Allocate an area of memory on the heap.
* DESCRIPTION   Allocate an area of memory, size as specified in D0.L, and
*               return the address of the allocated area in A0.L. D0 will be
*               set to an error code and the Z flag will be set if no errors
*               occurred, reset otherwise.
* INPUTS :
*               D0.L = Size, in bytes, of memeory area to be allocated
* OUTPUTS :
*               A0.L = Base address of the memory area allocated
*               D0 = Error code
*               Z flag set if no errors, unset otherwise.
*------------------------------------------------------------------------------
mem_alloc       movem.l d1-d3/a1-a3,-(a7)   ; Save working registers
                move.l  d0,d1               ; Space required has to be in D1
                moveq   #MT_ALCHP,d0        ; Set the trap
                moveq   #-1,d2              ; I want it for the current job
                trap    #1                  ; Do it
                movem.l (a7)+,d1-d3/a1-a3   ; Restore working registers
                tst.l   d0                  ; Set flags
                rts