
'32bit x86

static string Report


macro ReportStack(n)
'===================

  '
  scope
  '
  static sys stack[0X100],stackptr,e
  '
  'CAPTURE IMAGE OF UP TO 256 ENTRIES
  '
  '
  mov eax,n
  cmp eax,0x100
  (
    jle exit
    mov eax,0x100 'UPPER LIMIT
  )
  mov e,eax
  mov stackptr,esp
  lea edx,stack
  mov ecx,e
  mov esi,esp
  (
    mov eax,[esi]
    mov [edx],eax
    add esi,4
    add edx,4
    dec ecx
    jg repeat
  )
  sys i
  string cr=chr(13)+chr(10), tab=chr(9)
  '
  for i=1 to e
    report+=hex(stackptr+(i-1)*4,8) tab hex(i-1,2) tab hex(stack[i],8) cr
  next
  '
  end scope
  '
end macro

'====
'TEST
'====

function foo()

  push 0x44556677
  push 0x33445566
  push 0x22334455
  push 0x11223344
  ReportStack(8)

end function

Report+="Trace inside foo
"
foo()
print report
'putfile "s.txt",Report
