The LazyBoy Library Manual - AddExitProc

Part of the Library core group.

%imacro AddExitProc 1
Requires: label

Add an exit process to the exit chain.

Primarily this is for useage by the library. However, you could add things to the chain to ensure they are called when the program terminates. For example, you could close any open file handles by adding its Code Segment offset to the chain.

Processes in the chain are performed in the reverse order they are added. For example, the last process added will be the first one run at shutdown.

Removal of items from the chain is not supported at this time. They can only be added to the chain.

org 0x100 %include "lazy.inc" AddExitProc MESSAGE_1 AddExitProc MESSAGE_2 WriteLn "Hello, World!" Terminate ; last message to display on exit MESSAGE_1: WriteLn "The End" ret ; first message to display on exit MESSAGE_2: WriteLn "Goodbye cruel world!" ret LAZY_CODE

See also EXIT_CHAIN.