
  '=========================================
  'SAFE HUGE RECURSION WITH CUSTOMISED STACK
  '=========================================

 
  long espSave,espLimit,espSpace,i

  '-------------------------
  function f(long v) as long
  '=========================
  '
  'STACKSPACE LIMITED RECURSION
  '
  if esp>=espLimit then
    function=f(v+1) : inc i
  end if
  end function




  'USING A BSTRING FOR THE NEW STACK
  '=================================
  '
  espSpace=getmemory 4e7  'ALLOCATE BSTR SPACE FOR NEW STACK
  espSave=esp             'SAVE ORIGINAL STACK POINTER
  espLimit=espSpace+4096  'LOWER LIMIT FOR NEW STACK POINTER
  esp=espSpace+4e7        'SET NEW STACK POINTER
  '
  f(0)                    'CALL RECURSIVE FUNCTION
  '
  esp=espSave             'RESTORE ORIGINAL STACK POINTER
  freememory espspace     'FREE ALLOCATED STACK SPACE
  '


  print `Recursions: ` i  'SHOW RESULT


