community.borland.com

Article #15357: TASM 1.0 1.01 - ORDER OF ARG DIRECTIVE OPERANDS -

 Technical Notes Database

TN357D.txt   TASM 1.0 1.01 - ORDER OF ARG DIRECTIVE OPERANDS - 
Category   :Pascal
Platform    :All
Product    :Turbo Pascal  5.0 5.5

Description:
Q. In what order should the operands to the Arg directive
   appear?  Should they be the same as the order in the calling
   procedure or in reverse?
A. The answer depends upon the language that you're using and
   whether or not you're using the .model memory model, language
   option.

   Case 1:  You are using the full segment definitions or you are
            using the .model directive without specifying a
            language.

   The leftmost symbol in the Arg list is always nearest the top
   of the stack (TOS).  Thus, if your proc definition is

     myproc proc far
     arg first:word, second:word

   first will evaluate to [BP + 06H], the size of the four byte
   far return address plus the size of the two byte BP register
   pushed onto the stack.  The symbol, second, will evaluate to
   [BP + 08H], two bytes further from TOS.

   Again, the key point to remember is that the leftmost symbol
   is nearest TOS.

   If you are using Pascal or Basic, arguments are pushed from
   left to right onto the stack.  This is called Pascal calling
   syntax or Pascal calling conventions.  In this case, the last
   argument in the list is nearest TOS.  For example:

     {$F+}
     procedure myproc(one:integer; two:integer); external;
     {$F-}
     ...
     procedure myproc(first:integer; second:integer);
     ...

   The variable, first, is pushed onto the stack followed by
   second.  Thus, second is nearest TOS.  In this case, you would
   want to set up your Arg list as follows:

     myproc proc far
     arg second:word, first:word
     push bp
     mov  bp,sp

   The symbol, second, would evaluate to [BP + 06H], the symbol
   nearest TOS, and first would evaluate to [BP + 08H].

   To get the correct results with Basic or Pascal while using
   the simplified segment directives or .model without the
   language option, you must reverse the order of the arguments
   as they appear in the high level language calling routine's
   parameter list.

   If you are calling the Assembler routine from a C module and
   you are NOT using Pascal calling conventions, then the
   arguments are pushed onto the stack from right to left.  Thus,
   the leftmost argument is nearest TOS and there is no need to
   reverse the order to the symbols in the Arg list.

   If you wish to use Pascal calling conventions in Turbo C, use
   the -p option for TCC or the Pascal keyword.  Pascal calling
   syntax can also be enabled from within TC by setting the
   /Options/Compiler/Code generation/Calling convention to
   Pascal.

   Case 2:  You are using the .model memory model, language
            directive.

   All you need to do is put the Arg list symbols in the same
   order as they appear in the calling routine's parameter list.
   This is the easiest method, by far.  Remember to include the
   comma after the memory model in the .model directive and to
   specify the language.  If you are using Turbo Pascal, just use
   .model TPascal.


Reference:


7/16/98 4:35:31 PM
 

Last Modified: 01-SEP-99