The LazyBoy Library Manual - StackCheck

Part of the Library core group.

%imacro StackCheck 0-1
Prefers: nothing
Prefers: word

Check that the stack has not overflowed and has sufficient space.

This macro only performs checking when DEBUG is enabled. Otherwise it does not check the stack and generates no code in the binary.

When DEBUG is enabled, stack checking is automatically included with all documented macros provided by the library. If the stack does not have enough free space, the program will terminate with a stack overflow error.

StackCheck without any parameters assumes a set amount of free space is needed. The default is 32 bytes of free space as defined by the STACK_SAFETY_MARGIN setting in the lazydefs.inc file. It is not per program customizable setting.

Providing a paramater to StackCheck insures that additional space + the saftey margin is available on the stack.

There is a lot of overhead involved in constantly monitoring the stack. You should not have DEBUG when a program is released. It negatively impacts performance and increases the compiled binary byte size.

The following example will demonstrate stack overflow checking through the library macros. When executed, it will terminate with a stack overflow error.

org 0x100 %define DEBUG %include "lazy.inc" xor ax, ax GetStuck: push ax inc ax WriteLn "Pushed ", uint word ax, " word(s)." jmp GetStuck Terminate LAZY_CODE