Monitoring the Stack Using Assembly or C

Last reviewed: July 17, 1995
Article ID: Q51294
The information in this article applies to:
  • Microsoft FORTRAN for MS-DOS, versions 4.0, 4.1, 5.0 and 5.1
  • Microsoft FORTRAN for OS/2, version 4.0, 4.1, 5.0 and 5.1

SUMMARY

If, for any reason, you believe that the stack in a FORTRAN program is being corrupted, you can monitor the stack segment (SS) register and stack pointer (SP) register by using either the Microsoft Assembler package. Since CodeView may use the stack for its own purposes, this allows a more direct monitoring method.

A function for each package is shown below along with the appropriate interface statement. Each function returns an integer*4 to FORTRAN.

To extract the hexadecimal values from that integer, use a format statement something similar to the following example:

      write (*,'(1x,A7,1x,4Z,A1,4Z)')
     + 'seg:off',stackloc(),':',ISHC(stackloc(),16)

This write statement produces video output of the following form:

      seg:off 2BC0:111A

MORE INFORMATION

The assembly code and interface statement are shown below.

      interface to integer*4 function stackloc()
      end
      integer*4 stackloc

.model large .code public stackloc stackloc proc
       mov dx,ss
       mov ax,sp
       ret
stackloc endp
       end

The equivalent interface for the following QuickC with Assembler code is also listed below (keep in mind that this code must be compiled with the /AL switch for memory model compatibility):

      interface to integer*4 function stackloc [C,
     + alias:'_stackloc'] ()
      end
      integer*4 stackloc

int * stackloc(void)
{
        int j[2];

        _asm {
                mov     j[0],ss
                mov     j[1],sp
        }
        return j;
}


Additional reference words: kbinf 5.00 5.10 debug watch view
KBCategory: kbprg kbcode
KBSubcategory: FORTLngIss CLngIss MASMLngIss


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 17, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.