Monitoring the Stack Using Assembly or C

This article was previously published under Q51294
This article has been archived. It is offered "as is" and will no longer be updated.
SUMMARY
If, for any reason, you believe that the stack in a FORTRAN program isbeing corrupted, you can monitor the stack segment (SS) register andstack pointer (SP) register by using either the Microsoft Assemblerpackage. Since CodeView may use the stack for its own purposes, this allowsa more direct monitoring method.

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

To extract the hexadecimal values from that integer, use a formatstatement 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.codepublic stacklocstackloc proc       mov dx,ss       mov ax,sp       retstackloc endp       end				
The equivalent interface for the following QuickC with Assembler codeis also listed below (keep in mind that this code must be compiledwith the /AL switch for memory model compatibility):
      interface to integer*4 function stackloc [C,     + alias:'_stackloc'] ()      end      integer*4 stacklocint * stackloc(void){        int j[2];        _asm {                mov     j[0],ss                mov     j[1],sp        }        return j;}				
kbinf 5.00 nofps 5.10 debug watch view
Properties

Article ID: 51294 - Last Review: 01/06/2015 00:39:36 - Revision: 2.0

Microsoft FORTRAN Compiler 4.0, Microsoft FORTRAN Compiler 4.1, Microsoft FORTRAN Compiler 5.0, Microsoft FORTRAN Compiler 5.1, Microsoft FORTRAN Compiler 4.0, Microsoft FORTRAN Compiler 4.1, Microsoft FORTRAN Compiler 5.0, Microsoft FORTRAN Compiler 5.1

  • kbnosurvey kbarchive KB51294
Feedback