Article # 536, added by Geoworks, historical record
| first | previous | index | next | last |

How to have local variables in esp and still get the value of bp.




Q. If I'm writing an Esp procedure that uses local variables, how do
   I get the inital value of bp? 

A. When a procedure takes parameters in BP and uses local variables,
   BP can be saved before the stack frame is allocated.  Following
   are examples of strategies for saving the value of BP.

   1. Saving BP in a local variable 

   BP can be saved into the first push-initialized variable. 

      ; ^hbp = GState to draw to
      CircleVisDraw   method  dynamic CircleClass, MSG_VIS_DRAW
      gStateHandle    local   hptr.GState     push    bp
      count           local   word
                      .enter

                      ......
                      mov     di, ss:[gStateHandle]
                      call    GrDrawPoint

   2. Saving BP in another register 

      ; ^hbp = GState to draw to
      CircleVisDraw   method  dynamic CircleClass, MSG_VIS_DRAW
      count           local   word

                      mov     di, bp          ; ^hdi = GState
                      .enter
                      ......
                      call    GrDrawPoint