include masmdefs.hsm
include model.hsm

codedef CHKSTK
datadef

cstart  CHKSTK
cproc   _chkstk

if FUNC_L
	pop	cx			; get return offset
	pop	dx			; get return segment
else
	pop	cx			; get return offset
endif

	mov	bx,sp
	sub	bx,ax			; new position
	mov	sp,bx			; set new stack pointer

if FUNC_L
	push	dx			; push segment
	push	cx			; push offset
	ret				; far return to dx:cx
else
	jmp	cx			; return to cx
endif

cendp   _chkstk
cend    CHKSTK
        end
