Using ESP and EBP

It is possible in PowerBASIC to write your own procedure within an existing Sub or Function by manually coding the stack entry and exit.  This is a complicated area of assembler coding where it is very easy to crash the entire operating system if the code is not written correctly.  For example:

! CALL procname

' Other PowerBASIC code here

! JMP label       ; Jump over the procedure




! PUSH EBP        ; Preserve base pointer

! MOV EBP, ESP    ; Stack pointer into EBP


' Write your assembler code here


! MOV ESP, EBP    ; Restore stack pointer

! POP EBP         ; Restore base pointer




' Other PowerBASIC code here

There are other methods of preserving both ESP and EBP depending on personal taste and calling conventions, but you must save and restore the states of both registers if you choose to use a procedure of this type.  It is very important to note that ESP and EBP must always be preserved if they are to be altered, regardless of relative position of Inline Assembler code to BASIC statements.


See Also


MMX registers

Saving registers

Saving Registers at the Sub/Function level

Data types in registers