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

  1. ;****************************************************************************
  2. ; Filename: ATEXIT.ASM
  3. ;   Author: Peter Andersson
  4. ;  Version: 0.0
  5. ;  Created: 1995.03.13
  6. ;  Updated: -
  7. ;****************************************************************************
  8. ; Copyright Peter Andersson, 1994-1995.
  9. ; All rights reserved.
  10. ;****************************************************************************
  11. ; Function: ULONG @atexit(PFUNC);
  12. ;  Comment: @atexit registers an exit function which will be called when
  13. ;           your program ends. Up to 32 functions may be added to the exit
  14. ;           queue. The functions are executed in a last in, first out order.
  15. ;           This function will NOT be called when you exit your program with
  16. ;           @abort().
  17. ;    Input: Eax - function pointer (*func)()
  18. ;   Output: zero on success and nonzero when there are no more no space left.
  19. ;****************************************************************************
  20. ; Function: ULONG _cexit(VOID);
  21. ;  Comment: _cexit executes all registered @atexit() functions but does not
  22. ;           exit your program.
  23. ;    Input: nothing
  24. ;   Output: nothing
  25. ;****************************************************************************
  26.  
  27.     Include STDDEF.INC
  28.  
  29. MAX_ATEXIT = 32
  30.  
  31.     Codeseg
  32.  
  33. Proc    atexit  ,1
  34.         Mov    Edx,[ExitLength]
  35.         Cmp    Edx,MAX_ATEXIT
  36.         Jae    @@Exit01
  37.         Mov    [ExitQueue+Edx*4],Eax
  38.         Inc    Edx
  39.         Mov    [ExitLength],Edx
  40.         Clear    Eax
  41. @@Exit01:    Ret
  42. Endp
  43.  
  44.     Align    4
  45.  
  46. Proc    _cexit
  47. @@Loop01:    Mov    Ecx,[ExitLength]
  48.         Jecxz    @@Exit01
  49.         Dec    Ecx
  50.         Mov    [ExitLength],Ecx
  51.         Push    Offset @@Loop01
  52.         Jmp    [ExitQueue+Ecx*4]
  53.     Align    4
  54. @@Exit01:    Ret
  55. Endp
  56.  
  57.     Dataseg
  58.  
  59. ExitLength    Dd    0
  60. ExitQueue    Dd    MAX_ATEXIT Dup (?)
  61.  
  62.     End
  63.