community.borland.com

Article #15365: TASM 1.0 - RETURN FAILED FROM ASSEMBLY ROUTINE - T

 Technical Notes Database

TN365D.txt   TASM 1.0 - RETURN FAILED FROM ASSEMBLY ROUTINE - T
Category   :Pascal
Platform    :All
Product    :Turbo Pascal  4.0+

Description:
Q. When I call my Assembler routine from Turbo Pascal, everything
   works OK.  However, it does not seen to return properly.
   Why?
A. Any routine declared in the main program or in the
   implementation section of a unit, is by default a near call.
   Your Assembly language routine, assembled to an .OBJ file, is
   brought into the Pascal module as if it were declared and
   defined in that module.  Thus, by default, any call to that
   Assembly language routine is a near call.  If you have defined
   your Assembly language routine as a proc far, the Assembler
   will generate a corresponding RETF.  Thus, a near call is
   made, 4 bytes are popped off of the stack when the RETF is
   executed, and control will be returned to the wrong code
   segment.  If you want that call to be a far call in your
   Pascal module, be sure to bracket the function or procedure
   declaration with {$F+} and {$F-}.  Always make sure that the
   distance declarations and definitions agree.


Reference:


7/16/98 4:35:31 PM
 

Last Modified: 01-SEP-99