News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Very simple macro to display ESP.

Started by hutch--, December 17, 2014, 10:50:55 AM

Previous topic - Next topic

hutch--

Sometimes when you are writing low level procedures and in particular with FASTPROC procedures, you risk messing up the stack where the OS requires that the stack be the same value both before and after a procedure call. This is a very simple macro to test the before and after value of ESP. If they are the same before and after your procedure has balanced the stack, if its not you need to fix it.

It is possible to write C calling convention VARARG procedures in PowerBASIC but you have to code it completely from scratch as PB does not support C style VARARG and as with any C calling convention procedure, the stack must be balanced AFTER the procedure has returned. This simple macro will help get this stack balance right.

' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    MACRO showESP
      MACROTEMP dvar
      LOCAL dvar as DWORD
      ! mov dvar, esp
      StdOut "ESP register, Decimal = "+format$(dvar)+" - Hex = "+hex$(dvar,8)
    END MACRO

' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

FUNCTION PBmain as LONG

    showESP

    StdOut $CRLF+"Text Operation"+$CRLF

    showESP

    waitkey$

End FUNCTION

' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤