home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / PROG / PASCAL / TPA22.ZIP / TP&ASM.REF < prev    next >
Encoding:
Text File  |  1989-04-22  |  51.8 KB  |  1,345 lines

  1.  
  2.   TP&Asm           Integrated Compile-Time Assembler          Version 2.0
  3.   TP&Asm-M   Memory Mode Assembly Language Development Tool   Version 2.0
  4.  
  5.                 Copyright (c) 1989  Richard W. Prescott
  6.                           All Rights Reserved
  7.  
  8. ═══════ Built-In Assembly Language Support for Turbo Pascal Compilers ═══════
  9.  
  10.  All brand and product names mentioned herein are trademarks or registered
  11.                 trademarks of their respective holders.
  12.  
  13.   ┌─────────────────────────────────────────────────────────────────────┐
  14.   │ This file contains detailed reference information to enable you to  │
  15.   │ make effective use of the TP&Asm assembly environment.  For general │
  16.   │ information on getting started please see the file README.          │
  17.   └─────────────────────────────────────────────────────────────────────┘
  18.  
  19.  
  20. The following topics are described below:
  21.  
  22.     1. Command Line Options
  23.     2. The Assemble Statement
  24.     3. The Asm Statement
  25.     4. The Internal Statement
  26.     5. General Assembler Syntax
  27.     6. TP&Asm-specific Options
  28.     7. Supported Mnemonics
  29.  
  30.  
  31. The following additional topics are covered in the separate file
  32. TP&ASM2.REF:
  33.  
  34.     8. Error Messages
  35.     9. Trouble Shooting
  36.  
  37.  
  38.  
  39. 1. Command Line Options
  40.  
  41. In the following discussion, "TPA(M)" is used in statements that
  42. apply to both TPA and TPAM.
  43.  
  44. Use TPA if you have the TP&Asm Integrated Compile-Time Assembler,
  45. and TPAM if you have the TP&Asm-M Memory Mode Assembly Development
  46. Tool.
  47.  
  48. TP&Asm is invoked by typing one of the following lines at the DOS
  49. prompt:
  50.      TPA(M) <full command line>
  51.      TPA(M) <abbreviation> <options>
  52.      TPA(M)
  53.  
  54. Full Command Syntax:  At the DOS prompt, type
  55.  
  56.      TPA(M) <full command line>
  57.  
  58. where TPA(M) refers to EITHER TPA or TPAM, and <full command line>
  59. is any valid command line that could be executed directly from the
  60. DOS prompt.  TP&Asm will load into memory and then execute the
  61. command line, exactly as if it had been executed by DOS.  If a
  62. supported Turbo Pascal compiler is loaded at any point during the
  63. execution of the command line, you will see a message indicating
  64. that the assembler is active, and assembly support will be enabled.
  65. TP&Asm will not interfere with the operation of other non-compiler
  66. applications.
  67.  
  68. Examples: (the following examples apply equally well to TPA and
  69.            TPAM)
  70.  
  71.      TPA mybatch
  72.        run the batch file MYBATCH.BAT which changes directories and
  73.        then runs turbo.  Assembly support will be enabled.
  74.  
  75.      TPAM tpc myprog /r"param1 param2"
  76.        run TPC Version 4.0 to compile MYPROG.PAS and run in memory.
  77.        (Please see the Version 4.0 Owner's Handbook for information
  78.        on the /r command line option).  Assembly support will be
  79.        enabled.
  80.  
  81.      TPA command
  82.        load a copy of the command processor and return you to the
  83.        DOS prompt.  You have just made TP&Asm "Memory resident"!
  84.        Now EACH time you run a supported compiler, you will get a
  85.        message indicating that the assembler is active, and
  86.        assembly support will be enabled.  Each time you exit a
  87.        compiler, you will get a message indicating that the
  88.        assembler is inactive.  Type EXIT to quit the command
  89.        processor and remove TP&Asm from memory.  (You should not
  90.        run any RESIDENT programs from the command shell or you will
  91.        not be able to remove it from memory).
  92.  
  93. Abbreviated Syntax:  At the DOS prompt, type one of the following:
  94.  
  95.      TPA(M) c <options>
  96.      TPA(M) d <full command line>
  97.  
  98. TPA(M) c <options> is equivalent to:   TPA(M) tpc <options>,
  99. which runs the command line compiler with the specified options.
  100. Example:
  101.      TPA c myprog         (same as: TPA tpc myprog )
  102. (Please see the Turbo Pascal Owner's Guide for available options).
  103.  
  104. TPA(M) d <full command line> will run any valid DOS command line
  105. through debug with assembly support enabled.  This is primarily of
  106. interest to Turbo Version 4.0 users.  (Requires DEBUG.COM from
  107. your DOS disk).  Examples:
  108.      TPAM d turbo         (same as: TPAM debug turbo.exe )
  109.      TPA d tpc test /r    (same as: TPA debug tpc.exe test /r )
  110.  
  111. NOTE: the recommended method of using any debugger with TP&Asm is to
  112. run the debugger from TP&Asm:
  113.      TPA(M) <debugger> <parameters required by debugger>
  114. (Please be thoroughly familiar with the proper operation of your
  115. debugger before attempting this, since it is definitely possible to
  116. crash your system through improper use of a debugger.  Save your
  117. work frequently, and be prepared to reboot.)
  118.  
  119.  
  120. Quick Command Syntax:  At the DOS prompt, type
  121.  
  122.      TPA(M)
  123.  
  124. where TPA(M) refers to EITHER TPA or TPAM.  TP&Asm will load into
  125. memory and then execute TURBO.EXE, exactly as if you had typed
  126. "turbo" at the DOS prompt.  You will see a message indicating that
  127. the assembler is active, and assembly support will be enabled.
  128. ( This is the same as executing:  TPA(M) TURBO ).
  129.  
  130.  
  131.  
  132.  
  133. 2. The Assemble Statement
  134.  
  135. The syntax for the assemble statement is:
  136.  
  137.     Assemble  <remainder of line must be empty>
  138.  
  139.        <Standard Assembly language statements>
  140.  
  141.     End
  142.  
  143. Use of a semicolon ";" after the final "End" is governed by
  144. standard Pascal statement syntax.  Assembly ends with the first
  145. "End" encountered in the mnemonic field.  The entire line is then
  146. passed on to the compiler, permitting use of an Assemble statement
  147. in either clause of an "IF .. THEN .. ELSE" conditional statement.
  148.  
  149. The keyword "Assembly" is permitted as a synonym for "Assemble".
  150. This is useful to avoid misleading constructions like:
  151.      IF <Pascal Condition> THEN Assemble
  152. which gives the false impression of conditional assembly.  True
  153. conditional assembly is possible using the PAS statement described
  154. in the section TP&Asm-specific options.  Conditional execution of
  155. an assembly block is more clearly indicated by:
  156.      IF <Pascal Condition> THEN Assembly
  157.  
  158. The Assemble statement can be used in any situation where an Inline
  159. statement would be valid, including in the definition of (Assembly)
  160. Inline directive/MACROs.
  161.  
  162. Examples:
  163.  
  164.  {- Conditional execution of assembly code based on runtime value of x: }
  165.   IF x > 0 THEN Assembly
  166.     : <assembly statements>
  167.   End  {without semicolon}  ELSE Assembly
  168.     : <assembly statements>
  169.   End; {requires semicolon}
  170.  
  171.  {- Define an (Assembly) Inline directive/MACRO: }
  172.   PROCEDURE ClearInterrupts;
  173.   Assemble
  174.     Cli
  175.   End; {MACRO ClearInterrupts}
  176.  
  177.  {- Define a callable procedure with assembly code: }
  178.   PROCEDURE PrintScreen;
  179.   BEGIN
  180.     {- Pascal statements may be placed before ... -}
  181.     Assemble
  182.       Int 5
  183.     End; {Assemble}
  184.     {- ... or after the assembly code -}
  185.   END; {PrintScreen}
  186.  
  187.  
  188. Assembly sections may be mixed freely with other Pascal statements
  189. throughout the statement part of a block.  Transfer between Pascal
  190. and assembly sections is freely permitted:
  191.  
  192.  ■ A Pascal label may be specified as the target of any assembly
  193.    Call, Jmp, Loop, or conditional jump.  As with the Pascal "Goto"
  194.    statement, the label must be defined in the current block.
  195.  
  196.  ■ An assembly label may be specified as the target of a Pascal
  197.    "Goto" statement.  The target label must be declared in a
  198.    standard Pascal "Label" statement.  (Assembly labels which are
  199.    referenced only within the current Assemble statement need not
  200.    be declared).
  201.  
  202.  ■ Pascal Procedure and Function identifiers may be specified as
  203.    the target of any assembly Call (or Jmp), or as immediate data
  204.    offsets in assembly data manipulation instructions, eg:
  205.          Mov Dx,PasProc ;load Ofs(PasProc) into Dx
  206.    The Procedure or Function must be defined in the current program
  207.    or in a Unit specified in the Uses clause.  Assembly references
  208.    are fully recognized by the Turbo smart linker.
  209.  
  210.   "System" Procedures and Functions do not use true PROC Calls and
  211.    therefore cannot be called from assembly language, either
  212.    directly or indirectly, except using "PAS" as described below.
  213.  
  214.  ■ The assembly keyword "PAS" may be used to insert single or
  215.    multiple line Pascal statements within an assembly section.
  216.    See the section entitled TP&Asm-specific options.
  217.  
  218. As with the Inline statement, the registers BP, SP, SS, and DS
  219. should be restored before execution of any Pascal statements,
  220. including Procedure calls and "PAS" statements.
  221.  
  222. Please see the numerous .PAS files on the distribution disk
  223. (archive TP-ASM.ZIP, available on CompUServe) for additional
  224. examples of Assemble statement usage.
  225.  
  226.  
  227. 3. The Asm Statement
  228.  
  229. Situations that require only a single line of assembly code
  230. may be more concisely specified using an "Asm" statement.  The
  231. keyword "Asm" is used to instruct the compiler that the remainder
  232. of the current line is to be interpreted as an assembly language
  233. statement, and that the following line is to be interpreted as a
  234. Pascal statement.
  235.  
  236. As with the Assemble statement, the use of a semicolon ";" is
  237. governed by standard Pascal statement syntax, permitting use of
  238. an Asm statement in either clause of an "IF .. THEN .. ELSE"
  239. conditional statement.
  240.  
  241. The Asm statement can be used in any situation where an Inline
  242. statement would be valid, including in the definition of (Assembly)
  243. Inline directive/MACROs.
  244.  
  245. Examples:
  246.  
  247.  {- Single line assembly code in Pascal conditional statement: }
  248.   IF x > 0 THEN Asm Push PasVar1
  249.            ELSE Asm Push PasVar2; {comment permitted here}
  250.  
  251.  {- Define an (Assembly) Inline directive/MACRO: }
  252.   PROCEDURE ClearInterrupts;  Asm Cli;
  253.  
  254.  {- Define a callable procedure with assembly code: }
  255.   PROCEDURE PrintScreen;
  256.   BEGIN
  257.     {- Pascal statements may be placed before ... -}
  258.     Asm Int 5;
  259.     {- ... or after the assembly code -}
  260.   END; {PrintScreen}
  261.  
  262.  
  263.  
  264. 4. The Internal Statement
  265.  
  266. The Internal statement is intended as a convenient mechanism for
  267. moving working External assembly code into your program, or for
  268. developing assembly code intended for final compilation with an
  269. external assembler.  (Note however that the Assemble statement
  270. provides an equally powerful mechanism for using assembly language
  271. which has fewer limitations and is considerably easier to use,
  272. allowing, for example, direct reference to procedure and function
  273. parameters by name).
  274.  
  275. First, please refer to the Version 4 Owner's Handbook or Version 5
  276. Reference Guide for the syntax for using EXTERNAL programs.  The
  277. following discussion assumes you are converting an existing EXTERNAL
  278. program to INTERNAL.
  279.  
  280. For Internal Proc/Functions defined in a PROGRAM, the following
  281. changes are required:
  282.  
  283.   1)  Remove or comment out the Link directive {$L ...}
  284.       Internal Proc/Functions are automatically linked by the Turbo
  285.       smart linker, with dead code removal on a Proc by Proc basis.
  286.  
  287.   2)  Replace the word "External" with "Forward" in the
  288.       Proc/Function heading.
  289.  
  290.   3)  The Internal statement should be placed somewhere following
  291.       the forward declaration and before the PROGRAM "BEGIN" block.
  292.  
  293. For Internal Proc/Functions defined in a UNIT, the following
  294. changes are required within the IMPLEMENTATION section:
  295.  
  296.   1)  Remove or comment out the Link directive {$L ...}
  297.       Internal Proc/Functions are automatically linked by the Turbo
  298.       smart linker, with dead code removal on a Proc by Proc basis.
  299.  
  300.   2a) For PRIVATE Proc/Functions which are defined only in the
  301.       implementation section, replace the word "External" with
  302.       "Forward" in the Proc/Function heading.
  303.  
  304.   2b) For PUBLIC Proc/Functions which are defined in the interface
  305.       section, remove or comment out the entire Proc/Function
  306.       heading in the implementation section.
  307.  
  308.   3)  The Internal statement should be placed in the implementation
  309.       section somewhere following the forward declaration (if present)
  310.       and before the Unit "BEGIN" block (if present).
  311.  
  312. Ths syntax required in the INTERFACE section of a Unit is the same
  313. as for External.
  314.  
  315. The full syntax for the Internal statement is given below.
  316.  
  317. Examples:
  318.  
  319. {- The following code section implements an Internal PROC in a    -}
  320. {- PROGRAM or as a PRIVATE Proc in a Unit IMPLEMENTATION section. -}
  321.  
  322.         PROCEDURE PrintScreen; Forward;
  323.  
  324.         Internal Print
  325.         CODE Segment
  326.         PrintScreen PROC NEAR
  327.           Int 5
  328.           Ret
  329.         PrintScreen ENDP
  330.         CODE ENDS
  331.         END
  332.  
  333.         BEGIN {MAIN program or UNIT initialization}
  334.           PrintScreen;
  335.         END.
  336.  
  337. {- The following code defines a unit with a single public PROC    -}
  338. {- which is implemented using an Internal statement.              -}
  339.  
  340.         Unit PrtScr;
  341.         interface
  342.           PROCEDURE PrintScreen;
  343.  
  344.         implementation
  345.           Internal Print
  346.           CODE Segment
  347.           PrintScreen PROC FAR
  348.             Int 5
  349.             Ret
  350.           PrintScreen ENDP
  351.           CODE ENDS
  352.           END
  353.  
  354.         END. {Unit PrtScr}
  355.  
  356.  
  357.  
  358. The following syntax description is admittedly somewhat obtuse;
  359. It is intended to be read in the context of a working External
  360. procedure or function.  (Most external assembly code written for
  361. Turbo Versions 4.0 or 5.0 should already match this syntax).
  362.  
  363. The syntax for the Internal statement is:
  364.  
  365.     Internal <DataName> <remainder of line must be empty>
  366.  
  367.       Data Segment <options (ignored)>          \
  368.         <data allocation and EXTRN statements>    > optional
  369.       Data ENDS                                 /
  370.  
  371.       Code Segment <options (ignored)>
  372.         <optional assembler overhead statements (ignored)>
  373.  
  374.         <ProcName1> PROC <optional Near/Far specification>
  375.           <Standard Assembly language statements>
  376.           <MUST include at least one "RET <ParamSize>">
  377.         <ProcName1> EndP
  378.  
  379.         <additional PROC/ENDP sections>           > optional
  380.  
  381.       Code ENDS
  382.  
  383.       END <optional text (ignored)>
  384.  
  385. (Note: "DataName" must not duplicate any other Pascal identifier
  386.         used in your program).
  387.  
  388. Please Note: assembly ends with the first "End" encountered in the
  389. mnemonic field.  Everything to the right of "End" is ignored, and
  390. the next line will be treated as the start of a new Pascal
  391. statement.
  392.  
  393. It is the programmer's responsibility to insure that the assembly
  394. code matches the syntax required for external assembly code for the
  395. particular compiler version being used, with the following
  396. exception:
  397.  
  398.   All GLOBAL Pascal identifiers that have been defined prior to the
  399.   Internal statement may be referenced by name, without the need
  400.   for an EXTRN statement.  (TP&Asm ignores all EXTRN statements).
  401.   This includes references involving UnitName and record component
  402.   qualifiers, which are not permitted in EXTERNAL routines.
  403.  
  404. In particular, the programmer must insure that parameters and
  405. function results are correctly referenced relative to a properly
  406. initialized base or index register, and that parameters and/or
  407. function results are removed from the stack on exit as required by
  408. the particular compiler version being used.  Again, this should
  409. automatically be true for working external code designed for that
  410. compiler version.
  411.  
  412. Please see the file INTERNAL.PAS on the distribution disk for
  413. an example of an Internal statement which contains assembly code
  414. for both a Procedure and a Function.
  415.  
  416.  
  417. Note:
  418. In prior versions of TP&Asm each Internal PROC was implemented as
  419. a standard Pascal Procedure or Function, with additional code added
  420. as necessary to reverse the effects of the standard Procedure entry
  421. code.  Beginning with Release 2, TP&Asm builds Internal PROCs with
  422. no entry or exit code.  (In the examples above, for example, the
  423. procedure PrintScreen will consist of precisely 3 bytes of code).
  424.  
  425.  
  426.  
  427.  
  428. 5. General Assembler Syntax
  429.  
  430. This section is NOT intended to be an assembly language tutorial.
  431. It contains only a few brief notes intended to compare TP&Asm
  432. syntax requirements with the requirements of other assemblers you
  433. may own or be familiar with.
  434.  
  435. Because of its quick feedback and ability to freely mix Pascal and
  436. Assembly statements, TP&Asm is an excellent tool to use in learning
  437. Assembly language.  Please, however, plan to obtain a separate
  438. tutorial or reference on the use of 8086/88 Assembly language.
  439.  
  440. The assembler I use and recommend for stand-alone and/or linkable
  441. assembly language program/modules is A86, a full featured shareware
  442. assembler written by Eric Isaacson.  It comes complete with a very
  443. nice reference manual on disk, which, together with a few working
  444. sample programs, MAY be all you need to learn the basics of assembly
  445. language programming.
  446.  
  447.  
  448. General notes:
  449.  
  450. The basic syntax of a TP&Asm assembly statement is:
  451.  
  452. <optional label> <mnemonic> <operands> <optional comment>
  453.  
  454. These language elements can be upper or lower (or mixed) case, and
  455. may be placed in any position on the line, separated from each
  456. other by at least one space or tab.
  457.  
  458. The comment, if present, must begin with a semicolon and extends to
  459. the end of the line.  TP&Asm ignores everything following the
  460. semicolon, except as noted below under TP&Asm-specific options.
  461.  
  462. The label, if present, must not duplicate any Pascal identifier
  463. used in your program, and must be unique from other labels used in
  464. the same assemble statement, with the following exception:  For
  465. compatibility with A86, labels which consist of a single letter
  466. followed by any number of decimal digits (L1, P253, etc) are
  467. considered to be "Local labels" which may be redefined and reused.
  468. Code labels must end with a colon, except for PROC statements, in
  469. which a colon is optional.  Data labels must not end with a colon.
  470.  
  471. The mnemonic can be any standard 8086 mnemonic, optionally prefixed
  472. by one of the following:
  473.  
  474.   LOCK
  475.   A segment override: Cs, Ds, Es, or Ss
  476.   A string repeat prefix: Rep, RepZ, RepNZ, RepE, or RepNE
  477.  
  478. Use of a colon after the prefix is optional.  Prefixes may be
  479. placed on the preceding line, if desired.  It is generally an error
  480. to specify more than one prefix for the same instruction (in the
  481. sense that the processor may not do what you intended), however
  482. TP&Asm supports all combinations of one segment override with one
  483. string prefix, by converting the combination to a loop as
  484. illustrated below:
  485.  
  486.   RepE Cs Movsb       is converted to        L0: Cs Movsb
  487.                                                  LoopE L0
  488.  
  489. which moves bytes from Cs:[Si] to Es:[Di].  (If the loop technique
  490. is not used, "RepE Cs Movsb" may not repeat, and "Cs RepE Movsb"
  491. may take the first byte from Cs:[Si], and subsequent bytes from the
  492. default Ds:[Si] - probably not what you intended).  Note that the
  493. default (Es) DESTINATION segment for string operations cannot be
  494. overridden - this is a requirement of the processor, not TP&Asm.
  495.  
  496. A full list of supported mnemonics is provided below.  The file
  497. USAGE.PAS contains one or more examples of correct usage of each
  498. of the supported mnemonics.
  499.  
  500.  
  501. Operands refers to any operands required by the mnemonic, separated
  502. by commas.  Either source or destination operand may be prefixed by
  503. a segment override, where again, use of a colon is optional:
  504.  
  505.   Mov Ax,Es:[Di]
  506.  
  507. If the size of the operand (Byte, Word, or DWord) is not known to
  508. the assembler, or if you wish to use an operand differently than it
  509. was defined, you must place one of the following size specifiers
  510. before the operand (specifiers on the same line are synonyms):
  511.  
  512.     B          Byte Ptr
  513.     W          Word Ptr
  514.     D          DWord Ptr
  515.  
  516. Examples:
  517.  
  518.   Mov Ax,ByteVar   ; Syntax error if you defined VAR ByteVar: BYTE;
  519.   Mov Ax,W ByteVar ; Load Ax with two bytes beginning with ByteVar
  520.   Mov W Ax,ByteVar ; Same as above, overrides original definition
  521.  
  522.  
  523. The following conventions apply regarding numeric operands:
  524.  
  525.   As with other assemblers, all numbers must begin with a DECIMAL
  526.   digit. (Thus Ch is a register, and 0Ch is a hexidecimal number).
  527.  
  528.   For compatibility with A86, all numbers that begin with "0" are
  529.   assumed to be hexidecimal, whether or not there is a trailing
  530.   "h".  (Use Radix 10 to disable this assumption in the current
  531.   assemble/internal statement).
  532.  
  533.   For compatibility with INLINE.COM, all numbers that begin with
  534.   "$" are hexidecimal (and should NOT have a trailing "h").
  535.  
  536.   The Radix (or .Radix) statement may be used to specify the
  537.   default base for numbers which would otherwise be ambiguous,
  538.   namely, decimal digits without leading "$" or trailing "H".
  539.   Use "Radix 10" to specify decimal, "Radix 16" for hexidecimal,
  540.   and "Radix" to return to the default (leading 0 hexidecimal,
  541.   otherwise decimal).
  542.  
  543.   TP&Asm does not support binary numeric operands.  Please convert
  544.   Binary operands to Hexidecimal.
  545.  
  546.   TP&Asm supports 4-function arithmetic on immediate (constant,
  547.   NON-Data) operands, plus BIT and BY for compatability with A86.
  548.   Standard order of evaluation applies, but may be overridden
  549.   through the use of parentheses:
  550.  
  551.     Mov Al,2+3*6   ; same as Mov Al,20  (evaluate 3*6 first)
  552.     Mov Al,(2+3)*6 ; same as Mov Al,30  (evaluate 2+3 first)
  553.  
  554.  
  555. Notes on Use of Offsets and SEG DATA as numeric operands:
  556.  
  557.   Within the FIRST code block of a Program or Unit, the offset of
  558.   any assembly code or data label may be used in any instruction
  559.   which requires immediate data:
  560.  
  561.     Mov Ax,Offset AssemblyDataLabel
  562.     Sub Bx,AssemblyCodeLabel
  563.  
  564.   References to assembly Code labels refer to the OFFSET of the
  565.   labeled instruction within the current code segment.  The modifier
  566.   "Offset" is not required.  References to Data labels refer to the
  567.   CONTENTS of the labeled location unless preceded by the modifier
  568.   "Offset".
  569.  
  570.   If the first code block is a CsData statement as described in the
  571.   section TP&Asm-specific Options, the Contents or Offset of any
  572.   CsData Data label may be referenced in any subsequent Procedure
  573.   or Function, as well as in the main Program or Unit BEGIN block:
  574.  
  575.     Cmp Bx,Offset CsDataLabel
  576.  
  577.   Reference to Pascal LABEL Offsets is not permitted.
  578.  
  579.   Throughout each Program or Unit, the offset of any Pascal
  580.   Procedure, Function, or Variable may be used in any instruction
  581.   which requires immediate data, with the following exceptions:
  582.  
  583.     1) Byte references to Pascal Offsets are not permitted.  For
  584.        example, "Mov Al,Offset PascalSymbol" is not permitted even
  585.        if Ofs(PascalSymbol) is in [0..127].
  586.  
  587.     2) "Offset PascalSymbol" is not permitted as immediate data
  588.        when the Destination operand is a Pascal Variable.  For
  589.        example, "Add PascalVariable,Offset PascalSymbol" is not
  590.        permitted.  The following technique must be used:
  591.  
  592.          Mov Reg,Offset PascalSymbol
  593.          Add PascalVariable,Reg
  594.  
  595.   References to Pascal Procedure and Function identifiers refer to
  596.   the OFFSET of the Proc/Function within its code segment (except
  597.   when SETTING Function Results as described below).  The modifier
  598.   "Offset" is not required.  References to Pascal VAR and (Typed)
  599.   CONST identifiers refer to the CONTENTS of the Data Segment
  600.   location unless preceded by the modifier "Offset":
  601.  
  602.     Mov Ax,Offset PascalVariable
  603.     Dw PascalProcedure,PascalFunction
  604.  
  605.   The construct "SEG DATA" may be used in any assembly instruction
  606.   which requires immediate data, with the exceptions that Byte
  607.   references to "SEG DATA" are not permitted.  For example, to
  608.   restore the Turbo DS within a customized interrupt routine:
  609.  
  610.     Mov Ax,SEG DATA
  611.     Mov Ds,Ax
  612.  
  613.  
  614. Notes on Absolute Code Segment References:
  615.  
  616.   TP&Asm permits assembly data to be freely allocated and referenced
  617.   throughout the FIRST code block in each Program or Unit (that is,
  618.   the FIRST true Procedure or Function in a Program or Unit, or the
  619.   main BEGIN block of a Program or Unit with no Procedures or
  620.   Functions defined).  Data labels are retained in the symbol table
  621.   throughout the first code block so that all assembly sections can
  622.   reference the allocated data.  This data is considered local to
  623.   the first code block and is not available to subsequent Procedures
  624.   and Functions.
  625.  
  626.   Since Turbo Versions 4 and 5 use "smart linking", it is generally
  627.   not possible to accurately specify the location of any but the
  628.   FIRST Proc/Function in a Program or Unit.  For that reason, TP&Asm
  629.   does not permit reference to assembly Data allocated in subsequent
  630.   Procedures or Functions.  Attempts to do so will result in the
  631.   error "Invalid Absolute CSeg Reference".
  632.  
  633.   Use of assembly data definition is seldom necessary, and should
  634.   generally be avoided in favor of using Pascal data defined via
  635.   VAR or (Typed) CONST statements.
  636.  
  637.   The files DEMONEW.PAS and DOSEXEC.PAS in the archive TPA2-A.ARC
  638.   contains examples using data allocated in the first Procedure of
  639.   a Program.
  640.  
  641.  
  642. Notes on Forward References in Data Manipulation Instructions:
  643.  
  644. TP&Asm is somewhat restrictive regarding the use of forward
  645. references in Data Transfer, Arithmetic, and Logic instructions
  646. (as opposed to Control Transfer instructions).  In particular:
  647.  
  648.   All Pascal identifiers used as operands must be defined PRIOR
  649.   TO the current Assemble or Internal statement.  (This is
  650.   consistent with the standard Pascal requirement that all
  651.   identifiers be defined).
  652.  
  653.   The Internal DATA SEGMENT section, if present, must preceed the
  654.   CODE SEGMENT section.
  655.  
  656.   FORWARD reference to assembly Data labels is not permitted.  (All
  657.   data definitions must be placed PRIOR TO the first reference).
  658.   This is not really a restriction for assembly language within a
  659.   Pascal program.  The only reason you might be tempted to have data
  660.   at the end of your assembly code is to reduce the size of the
  661.   compiled program by placing buffers and other uninitialized data
  662.   after the last Code statement.  Since your last assembly statement
  663.   can never be assumed to be the last code statement in your Pascal
  664.   program, this is simply not allowed.  Instead, define
  665.   uninitialized data in Pascal:
  666.     Var Buffer: ARRAY[1..20000] OF BYTE;
  667.  
  668.   Forward reference to CODE labels in the FIRST code block of a
  669.   Program or Unit is permitted.  For example:
  670.  
  671.     Add Ax,ForwardLabel - $
  672.  
  673.   is permitted within the FIRST true Procedure or Function in
  674.   a Program or Unit.
  675.  
  676.  
  677. Notes on Operands to Control Transfer Statements:
  678.  
  679.   Control Transfer statements include the unconditional Jmp and
  680.   Call, and the conditional Jumps (jZ, jPE, jCXZ, etc) and Loops
  681.   (Loop, LoopNE, etc).  The operand to a Direct control transfer
  682.   statement must be a SINGLE symbol name which is either:
  683.  
  684.     1) an assembly code label (including PROCs) within the current
  685.        Assemble statement (or the current major PROC of the current
  686.        Internal statement),
  687.     2) a Pascal LABEL within the current block, or
  688.     3) (for Call and Jmp only) a Pascal or Internal Procedure or
  689.        Function Identifier.
  690.  
  691.   The operand to an Indirect control transfer statement may be any
  692.   valid register or memory expression of the appropriate (Word or
  693.   DWord) size.
  694.  
  695.   The JMP modifiers "Short" and "Long" (as used by A86) are
  696.   permitted but are ignored.  TP&Asm performs automatic minimum
  697.   Jump-Sizing for all backward AND FORWARD Jumps and Loops (Jmp,
  698.   jZ, jAE, jCXZ, Loop, LoopNZ, etc) within the current code block.
  699.   A 3-, 5-, or 7-byte instruction sequence will automatically be
  700.   generated if the target label is not within range of a 2 byte
  701.   instruction.
  702.  
  703.   This includes automatic shortening of unconditional jumps:
  704.  
  705.      Jmp CloseBy    .. becomes ..    Jmp Short CloseBy ;2 bytes
  706.  
  707.   Automatic 5 byte "IF <Cond> Jmp" for backward AND FORWARD
  708.   conditional jumps out of range:
  709.  
  710.      jNZ FarAway    .. becomes ..        jZ >L0        ;2 bytes
  711.                                          Jmp FarAway   ;3 bytes
  712.                                      L0:
  713.  
  714.   And automatic 7 byte instruction sequences for backward AND
  715.   FORWARD jCXZ & Loop's out of range:
  716.  
  717.      Loop FarAway   .. becomes ..        Loop >L0      ;2 bytes
  718.                                          Jmp Short >L1 ;2 bytes
  719.                                      L0: Jmp FarAway   ;3 bytes
  720.                                      L1:
  721.  
  722.   Note that TP&Asm does NOT pad forward jumps with NOP instructions,
  723.   but rather always builds the smallest possible instruction.
  724.  
  725.   The automatic Jump-Sizing feature is not enabled in (Assembly)
  726.   Inline Directive/MACROs.  As described in the Turbo 4.0 and 5.0
  727.   manuals, Inline Directives are intended for short sections of code
  728.   which are unlikely to exceed 127 bytes.  TP&Asm generates an error
  729.   if a conditional jump out of range is attempted in an (Assembly)
  730.   Inline Directive/MACRO.
  731.  
  732.   Pascal Proc/Functions can be called from assembly language using
  733.   direct or indirect calls:  "Call PasProc"  will generate:
  734.  
  735.     1) a NEAR Direct call if PasProc is a Procedure or Function
  736.          defined in the CURRENT Program or implementation section in
  737.          the {$F-} state.
  738.     2) a FAR Direct call if PasProc is a Procedure or Function
  739.          defined in another Unit or in the CURRENT Program or
  740.          implementation section in the {$F+} state.
  741.     3) a NEAR Indirect call if PasProc is a Word (Integer) Variable.
  742.          PasProc must be initialized with the Ofs of a NEAR {$F-}
  743.          Procedure or Function in the CURRENT Program or Unit.
  744.     4) a FAR Indirect call if PasProc is a Pointer or Procedure
  745.          Variable.  PasProc must be initialized with the Addr of a
  746.          FAR {$F+} Procedure or Function.
  747.  
  748.   The default action in (3) may be overridden using the FAR
  749.   modifier:  "Call Far PasProc"  will generate:
  750.  
  751.    3b) a FAR Indirect call if PasProc is any Pascal Variable.
  752.          MemL[DSeg:Ofs(PasProc)] must be initialized with the Addr
  753.          of a FAR {$F+} Procedure or Function.
  754.  
  755.   The default action in (4) may be overridden using the NEAR
  756.   modifier:  "Call Near PasProc"  will generate:
  757.  
  758.    4b) a NEAR Indirect call if PasProc is any Pascal Variable.
  759.          MemW[DSeg:Ofs(PasProc)] must be initialized with the Ofs of
  760.          a NEAR {$F-} Procedure or Function in the CURRENT Program
  761.          or Unit.
  762.  
  763.   The default actions in (1) and (2) may not be overridden, as
  764.   this would always result in a mismatch between the Call and Ret
  765.   instructions.
  766.  
  767.   For completeness, TP&Asm permits an unconditional JMP to a Pascal
  768.   Procedure or Function.  This would be useful only in very obscure
  769.   situations, and should otherwise be avoided.  A 3-byte Near jump
  770.   or 5 byte Far jump is built, as necessary.  The modifier "Short",
  771.   if present, is ignored, since the Turbo linker does not permit
  772.   Byte references.
  773.  
  774.  
  775. Notes on setting Function Results:
  776.  
  777.   To facilitate the setting of Pascal function results within
  778.   assembly sections, Pascal Function identifiers of any simple TYPE
  779.   can be specified as the Destination operand of a MOV instruction:
  780.  
  781.     Mov ByteFunction,Al    - OR -     Mov PointerFunction,Ax
  782.                                       Mov PointerFunction+2,Dx
  783.  
  784.   The Function identifier should be thought of as representing a
  785.   local variable of the appropriate size which is stored in the
  786.   Stack segment and accessed relative to the Bp register.  As with
  787.   all local variables, the explicit specification of the [Bp] is
  788.   not required.
  789.  
  790.   Pascal String Function identifiers can be specified as the Source
  791.   operand in a Load Pointer (Les/Lds) instruction:
  792.  
  793.     Les Di,StringFunction ; Load Pointer to temporary storage area
  794.     Es Mov [Di],Cl        ; Put in Result Length
  795.     Inc Di                ; Point past length byte
  796.     Rep MovSB             ; Put in String
  797.  
  798.   String Function identifiers refer to the local Pointer Variable
  799.   which is pushed on the stack by the Calling procedure and which
  800.   references the temporary storage location established by the
  801.   Caller.
  802.  
  803.   You should not attempt to set a Function result from within a
  804.   nested sub-procedure.
  805.  
  806.  
  807. Notes on use of Qualified Identifier Syntax:
  808.  
  809.   TP&Asm supports the full qualified identifier syntax including
  810.   both UnitName and record component qualifiers, for example:
  811.  
  812.     Test Ax,DOS.FZero
  813.     Cmp Ax,UnitX.RecVar.NestRec.IntegerComponent
  814.  
  815.   UnitName qualifiers must be defined in a "Program" or "Unit"
  816.   statement.  (The symbol "PROGRAM" is not a valid qualifier).
  817.  
  818.   Embedded spaces are not permitted, so that the following would
  819.   generate syntax errors:
  820.  
  821.     Test Ax,DOS. FZero
  822.     Cmp Ax,UnitX.RecVar. NestRec.IntegerComponent
  823.  
  824.   Following a valid UnitName qualifier, the subsequent search
  825.   is limited to PASCAL identifiers in the given unit.  Likewise,
  826.   following a valid record variable with a trailing ".", the
  827.   subsequent search is limited to record components associated
  828.   with that variable.  This duplicates the compiler's symbol
  829.   search strategy, and permits references to record components
  830.   which duplicate assembly variables and reserved symbols.
  831.   Thus, if RegVar is of TYPE Registers (from the DOS unit), the
  832.   following is permitted:
  833.  
  834.     Mov Ax,RegVar.Ax  ;- ( ">" or "<" not required )
  835.  
  836.   (If you wish to specify a record variable offset which is not
  837.   a valid component name, including Pascal and assembly constants,
  838.   use "+" in place of ".".  Thus, if PasConst = 4 and AsmSym EQU 4,
  839.   the following statements are all equivalent:
  840.  
  841.     Add Ax,RegVar.Cx
  842.     Add Ax,RegVar+AsmSym
  843.     Add Ax,RegVar+PasConst  ;
  844.  
  845.   whereas "Add Ax,RegVar.PasConst" would generate a syntax error).
  846.  
  847.   The symbolic value of a record ComponentName is the numeric
  848.   offset of that component from the beginning of the record.  To
  849.   reference this value irrespective of any record variable, you
  850.   must prefix the ComponentName with a TypeDef qualifier.  For
  851.   example,  "Add Di,DateTime.Hour"  is the same as  "Add Di,6",
  852.   because 3 Integers (and hence 6 bytes) preceed Hour within the
  853.   record type DateTime.  Use of TypeDef qualifiers permits assembly
  854.   reference to Dynamic record variables.  For example, to refer
  855.   to RecPtr^.ComponentX, where RecPtr is a VAR of TYPE ^RecType:
  856.  
  857.     Les Di,RecPtr ; Load Pointer into Es:Di
  858.     Es Mov Ax,[Di]RecType.ComponentX ; apply ComponentName offset
  859.  
  860.   Note also that within a given Assemble/Internal statement, you can
  861.   define assembly equates, permitting references like the following:
  862.  
  863.     AsmPtr EQU W Es [Di]
  864.      :
  865.     Les Di,RecPtr ; Load Pointer into Es:Di
  866.     Mov Ax,AsmPtr.RecType.ComponentX ; apply ComponentName offset
  867.  
  868.   Reference to a ComponentName without a Record Variable or Record
  869.   Type qualifier is not permitted.
  870.  
  871.  
  872. The following additional notes regarding operands apply:
  873.  
  874.   Pascal identifiers used as operands may optionally be prefixed
  875.   by "<" or ">".  This is primarily for compatability with Dave
  876.   Baldwin's INLINE.COM, but also serves one other purpose: it
  877.   allows you to refer to Pascal identifiers which duplicate
  878.   assembler reserved symbols.  Thus:
  879.  
  880.     Mov Al,Ch  ; Places contents of Ch register into Al
  881.     Mov Al,>Ch ; Places value of Pascal variable Ch into Al
  882.     Mov Al,Ch1 ; Ch1 is not reserved - no ">" or "<" required
  883.  
  884.   For compatability with A86, "Local labels" (described above) used
  885.   as operands may be prefixed by ">" to force a forward jmp when
  886.   there is a prior definition:
  887.  
  888.     jNE L0  ; Backward jump if already defined (otherwise forward)
  889.     jNE >L0 ; Forward jump even if there is a prior definition
  890.  
  891.  
  892.  
  893.  
  894. Notes for users of A86, by Eric Isaacson:
  895.  
  896.   Multiple operands to Push, Pop, Inc, and Dec are supported.
  897.   Segment overrides can be specified for each operand:
  898.     Push [Si],Es:[Di],[Bx] ; uses default Ds for [Si] and [Bx]
  899.   Or a single segment override can be specified for all operands:
  900.     Es Push [Bx+2],[Bx]    ; uses Es override for both operands
  901.  
  902.   The final numeric operand to Inc and Dec is not supported.
  903.     Inc Ax,3 ; will a generate syntax error
  904.     Add Ax,3 ; use this instead
  905.  
  906.   The IF statement is supported, including "IF NCXZ" (for whatever
  907.   it's worth).
  908.  
  909.   Local labels are supported, as described above.  A local label
  910.   which is never redefined does not require a ">" for forward
  911.   references.
  912.  
  913.   Conditional Returns, Extensions to MOV, Operands to AAD/AAM, and
  914.   Single-Operand TEST's are not supported.
  915.  
  916.  
  917.  
  918. Notes for users of MicroSoft's MASM:
  919.  
  920.   TP&Asm supports the basic syntax used by the MicroSoft Macro
  921.   Assembler, at least, to the best of my ability to determine that
  922.   by studying assembly programs designed for MASM.  If you discover
  923.   any incompatabilities with commonly used MASM syntax, please let
  924.   me know.
  925.  
  926.   TP&Asm supports a number of extensions for compatability with
  927.   Eric Isaacson's A86 assembler, including multiple operands to
  928.   Push, Pop, Inc, and Dec, Reusable local labels, and convenient
  929.   abbreviations for Word Ptr, Byte Ptr, etc. (described above under
  930.   General Notes).  The following compatability extension has not
  931.   yet been described:
  932.  
  933.     IF <condition> <statement>  : the single statement specified
  934.       will execute if the condition holds at runtime.  Valid
  935.       conditions are those for which there is a conditional jump
  936.       instruction for the OPPOSITE condition. ("IF NCXZ" is allowed;
  937.       "IF CXZ" is not allowed since there is no jNCXZ instruction).
  938.  
  939.     Example:
  940.                                                 jZ L1
  941.       IF NZ Mov Result,FALSE ; same as -->      Mov Result,FALSE
  942.                                               L1:
  943.  
  944.  
  945. Notes for users of INLINE.COM, by Dave Baldwin:
  946.  
  947.   As noted above, TP&Asm permits the use of "$" as a hexidecimal
  948.   specifier, and allows (but does not require) ">" or "<" to be
  949.   used as a prefix to Pascal identifiers.  These were features of
  950.   the INLINE.COM version I have seen, and may or may not be
  951.   required in the current version.
  952.  
  953.   TP&Asm does not permit the use of BY, WO, and DW as abbreviations
  954.   for Byte Ptr, Word Ptr, and DWord Ptr.  (BY and DW are reserved
  955.   by the assembler for other purposes).  Use the unabbreviated
  956.   forms, or the abbreviations B, W, and D.
  957.  
  958.   Please see the MASM user's notes for a description of the IF
  959.   statement, not described under General Notes.
  960.  
  961.  
  962.  
  963.  
  964. 6. TP&Asm-specific Options
  965.  
  966. This section describes certain features that are unique to the
  967. TP&Asm/TP&Asm-M assembler.
  968.  
  969.  
  970. The Pas Statement
  971.  
  972. TP&Asm provides the assembly keyword "Pas" for inserting single
  973. or multiple line Pascal statements within an assembly section.
  974. This may be used as an alternative to:
  975.   1) breaking the Assemble section into two or more blocks, and
  976.   2) defining the target of any jumps which cross the Pascal code
  977.      in a Pascal Label statement.
  978.  
  979. To include one or more lines of Pascal statement(s) within an
  980. assemble statement, simply precede each line with the prefix
  981. "Pas".
  982.  
  983. Pascal statements may modify any of the following registers:
  984.    Ax, Bx, Cx, Dx, Di, Si, and Es
  985. Your assembly code should save and restore these registers as
  986. needed.
  987.  
  988. Example:
  989.  
  990.   Assemble
  991.      :
  992.     jNZ TargetLabel1
  993.      :
  994.     jAE TargetLabel2
  995.      :
  996.     Push Ax,Cx  ;preserve registers Ax and Cx
  997.     Pas BlockRead(InFile,Buffer,SizeOf(Buffer),BytesRead);
  998.     Pop Cx,Ax
  999.    TargetLabel2:
  1000.      :
  1001.    TargetLabel1:
  1002.      :
  1003.   End; {Assemble}
  1004.  
  1005.  
  1006. The Pas statement may be used to implement conditional assembly as
  1007. shown in the following example:
  1008.  
  1009.   Assemble
  1010.      :
  1011.    Pas {$IFDEF VER50}
  1012.     Call DosVersion ;This will assemble if VER50 is defined
  1013.    Pas {$ELSE}
  1014.     Mov Ah,30h      ;This will assemble
  1015.     Int 21h         ; if VER50 is NOT defined
  1016.    Pas {$ENDIF}
  1017.     Cmp Al,3
  1018.      :
  1019.   End; {Assemble}
  1020.  
  1021. Internal PROCs do not generate the standard Pascal procedure entry
  1022. code and therefore cannot safely execute Pascal statements.  For
  1023. this reason, the Pas statement is not permitted in an Internal
  1024. block.
  1025.  
  1026.  
  1027. The CsData Statement
  1028.  
  1029. Beginning with version 4, Turbo Pascal Typed Constants are no
  1030. longer stored in the Code segment.  This change was required, among
  1031. other reasons, because of the fact that Version 4 programs can have
  1032. multiple Code segments.  Nonetheless, in certain very specific
  1033. situations, it is useful to be able to place named data in the
  1034. current Code segment.  As described in the preceding section, TP&Asm
  1035. permits the allocation of Local data in the Code Segment within the
  1036. FIRST code block in any Program or Unit.
  1037.  
  1038. TP&Asm also permits the allocation of Global data in the current
  1039. Code Segment in a block beginning with the keyword "CsData".  The
  1040. CsData statement must be the FIRST Code block in the current Program
  1041. or Unit.  The syntax for the CsData statement is as follows:
  1042.  
  1043.       CsData  {remainder of line may contain a comment}
  1044.         :
  1045.        <Db, Dw, and/or Dd statements>
  1046.         :
  1047.       End;    {semicolon is required}
  1048.  
  1049. The CsData block is implemented as a "Procedure" with no executable
  1050. code, beginning at offset 0 within the current code segment.  All
  1051. references to the first data label (at offset 0) are passed to the
  1052. Turbo smart linker to insure inclusion of the entire CsData block in
  1053. the final compiled code.  Since the Turbo linker does not permit
  1054. nonzero offset references to Pascal Procedures and Functions,
  1055. references to subsequent data labels are processed directly and not
  1056. passed to the linker.  It is therefore essential that some reference
  1057. be made to the first data label if reference is made to any CsData
  1058. labels.  Simply order the data so that an unused data label is not
  1059. placed first in the CsData block, or force inclusion of the CsData
  1060. block with a statement of the form
  1061.                      "Mov Ax,FirstDataLabel"
  1062.  
  1063. The Unit DOS21_0A.PAS in the archive TP-TSR contains an example
  1064. of the CsData statement.  It is used to implement a customized
  1065. interrupt procedure which can chain to the original interrupt vector
  1066. rather than IRET to the calling program.  To permit this, the
  1067. original value of the interrupt vector must be stored in the Code
  1068. Segment so that ALL registers may be restored before issuing an
  1069. indirect "Jmp OldVector" via the stored address.  (Addresses stored
  1070. in the Data Segment are not accessible after Ds is restored).
  1071.  
  1072.  
  1073.  
  1074. TP&Asm Directives
  1075.  
  1076. TP&Asm Directives provide a mechanism for modifying the following
  1077. characteristics of the assembler:
  1078.  
  1079.     Use of Presumptions
  1080.     Treatment of Warning Errors
  1081.  
  1082. These modifications will remain in effect for the duration of the
  1083. current Assemble/Internal statement OR until reset by another
  1084. TP&Asm directive.  The combination <semicolon><sharp>, as in ";#",
  1085. is reserved by TP&Asm to indicate the beginning of a TP&Asm
  1086. directive.  The semicolon must be the first non-blank character
  1087. on the line.
  1088.  
  1089. Use of Presumptions.
  1090.  
  1091. ;#P+   Enable   Presumptions (default)
  1092. ;#P-   Disable  Presumptions
  1093.  
  1094. TP&Asm keeps track of any Segment Overrides and/or Base register
  1095. specifications necessary to reference your Pascal and Assembly
  1096. variables.  With presumptions enabled, these segment and base
  1097. specifications are automatically provided if you choose to omit them
  1098. in your data reference.  Thus you may use
  1099.  
  1100. Mov Ax,LocalVar       ; - OR -
  1101. Mov Ax,LocalVar[Bp]   ; Full Specification
  1102.  
  1103. if LocalVar is a Local Pascal variable in the current Proc/Function;
  1104.  
  1105. If CSegVar is an assembly variable in CsData block, (see above),
  1106. then you could use any of the following
  1107.  
  1108. Mov Ax,CSegVar
  1109. Mov Ax,Cs CSegVar     ; Full Specification  - OR -
  1110. Cs Mov Ax,CSegVar     ; Full Specification
  1111.  
  1112. to reference CSegVar.  In each case TP&Asm assembles the full
  1113. specification.  Using presumptions allows you to make most
  1114. references to Pascal and Assembly variables just as you do in
  1115. Pascal, without worrying about where the compiler stores these
  1116. variables.  The resulting assembly code has the form that would
  1117. be used in a straightforward ("tiny model") assembly program with
  1118. all data accessible from the Ds register.  Note that ASSUME
  1119. statements are unnecessary, and are ignored by TP&Asm.
  1120.  
  1121. The Directive ";#P-" allows you to disable presumptions in
  1122. situations where you believe the default specification is not
  1123. correct, or if you just don't feel comfortable with the idea that
  1124. the assembler is providing these specifications 'behind your back'.
  1125. When presumptions are disabled you must use the full specifications
  1126. as indicated in the examples above.
  1127.  
  1128. You should seldom find it necessary to disable presumptions,
  1129. however there are two situations that warrant closer attention.
  1130. The first applies to string operations (Movsb, Cmpsw, etc), and
  1131. the second applies to users who want to refer to Local variables
  1132. which are not in the current Proc/Function.
  1133.  
  1134. For String operations you must of course properly initialize the Es
  1135. register to the segment of the destination string.  In addition,
  1136. the assembler must determine if a segment override is necessary in
  1137. connection with the source address in the Si register.  If Si is
  1138. loaded with an Lds instruction:
  1139.  
  1140. Lds Si,MemoryReference
  1141.  
  1142. then TP&Asm will assume the Ds register is properly initialized
  1143. and will not provide a segment override.
  1144.  
  1145. If Si is loaded in one of the following fashions:
  1146.  
  1147. Lea Si,VarName         ; - OR -
  1148. Mov Si,Offset VarName
  1149.  
  1150. and Si is NOT MODIFIED before being used in a String operation, then
  1151. TP&Asm will automatically provide any necessary override.  Si is
  1152. considered to have been modified by any instruction which has Si as
  1153. DESTINATION operand, with the following exceptions:
  1154.    Test, Cmp, Inc, and Dec
  1155. (The first two do not modify their operands.  With the second two,
  1156. TP&Asm makes the reasonable assumption that the segment associated
  1157. with the Source address in Si should not change as a result of an
  1158. Increment/Decrement operation).
  1159.  
  1160. Example:
  1161.  
  1162. Xor Ch,Ch
  1163. Lea Si,LocalStringVar  ; Local Pascal VARs are stored on the Stack
  1164. Lodsb                  ; TP&Asm supplies Ss override
  1165. Mov Cl,Al
  1166. Rep Movsb              ; TP&Asm supplies Ss override and
  1167.                        ; converts double prefix to LOOP
  1168. Add Si,Bx              ; SI HAS BEEN MODIFIED
  1169.  ;- You have placed an address in Si for which it is impossible
  1170.  ;- for the assembler to Presume the proper segment
  1171.  ;- TP&Asm assumes you know what you're doing, and therefore
  1172.  ;- SUPPLIES NO OVERRIDE (Source will use the default Ds register),
  1173.  ;- but generates a Warning Error IF WARNINGS ARE ENABLED
  1174. Cmpsb                  ; TP&Asm supplies no override
  1175.  
  1176.  
  1177. You may determine if the assembler is providing a segment override
  1178. using ASMWATCH with Turbo 5.0.  The watch expression "CPU.CsIp^,m"
  1179. displays a hex dump beginning at current instruction.  If the first
  1180. byte of a repeated or non-repeated string instruction is $36 or $2E,
  1181. an override is being provided.
  1182.  
  1183.  
  1184. To reiterate, with respect to string operations with
  1185. Presumptions Enabled:
  1186.  
  1187.  1)  you must properly initialize the Es and Di Registers
  1188.  2a) Load Ds and Si using Lds:
  1189.      Lds Si,MemoryReference
  1190.  - OR -
  1191.  2b) Load Si only, using one of the following:
  1192.      Lea Si,VarName         ; - OR -
  1193.      Mov Si,Offset VarName
  1194.  3)  Subsequent statements SHOULD NOT MODIFY Si, until
  1195.      AFTER the string operation
  1196.  4)  you must restore Ds if it was modified
  1197.  
  1198. Or, with Presumptions Disabled:
  1199.  
  1200.  1)  you must properly initialize Es, Di, and Si
  1201.  2)  If the source string is not in the Data Segment, you must
  1202.      either set Ds to the segment of the Source string, or use
  1203.      an explicit segment override with the string mnemonic
  1204.  3)  you must restore Ds if it was modified
  1205.  
  1206.  
  1207. To reference LOCAL variables which are NOT in the current Procedure
  1208. or Function, the preferred method is to define a local variable in
  1209. the current Proc/Function and use Pascal as follows:
  1210.  
  1211. PROCEDURE Outer;
  1212. VAR SomewhatLocalVar;
  1213.  
  1214.   PROCEDURE Inner;
  1215.   VAR LocalVar;
  1216.   BEGIN
  1217.   {- if assembly code USES the value of SomewhatLocalVar: -}
  1218.     LocalVar := SomewhatLocalVar;
  1219.     Assemble
  1220.      < use LocalVar in place of SomewhatLocalVar >
  1221.     End; {Assemble}
  1222.   {- if assembly code needs to MODIFY SomewhatLocalVar: -}
  1223.     SomewhatLocalVar := LocalVar;
  1224. <etc>
  1225.  
  1226. With Turbo Versions 4 & 5 it is possible to make assembly references
  1227. to Local variables which are NOT in the current Proc/Function,
  1228. however: you will need to disable presumptions, properly initialize
  1229. the Bx register, and provide the full specification:
  1230.  
  1231. ;#P-
  1232. Mov  Bx,[Bp+4]  ; Initialize Bx to Caller's Stack Frame
  1233. Ss Mov Ax,SomewhatLocalVar[Bx]
  1234. ;#P+
  1235.  
  1236.  
  1237. Treatment of Warning Errors.
  1238.  
  1239. ;#W+   Halt on  Warnings
  1240. ;#W-   Ignore   Warnings     (default)
  1241.  
  1242. TP&Asm performs an extensive set of syntax checks on your assembly
  1243. code (including many that can only be detected at compile time), and
  1244. reports any such error on the standard compiler error line, with the
  1245. cursor placed on the line that caused the error.  The full list of
  1246. standard error messages is provided in the file TP&ASM2.REF.
  1247.  
  1248. In addition to these standard error messages there is a small set of
  1249. warning error messages, mostly having to do with possible errors in
  1250. the use of segment overrides, that will be generated only when
  1251. Warnings are enabled.  Warnings are normally disabled so as not to
  1252. interfere with (possibly) valid instructions.  Use the directive
  1253. ";#w+" to enable warnings and ";#w-" to disable them again.
  1254.  
  1255. The warning error messages are also listed, with brief explanations,
  1256. in the file TP&ASM2.REF.
  1257.  
  1258.  
  1259.  
  1260.  
  1261. 7. Supported Mnemonics
  1262.  
  1263. TP&Asm supports the following 8086 mnemonics and data definition
  1264. directives:
  1265.  
  1266.  AAA         AAD         AAM         AAS         ADC         ADD
  1267.  AND         CALL        CBW         CLC         CLD         CLI
  1268.  CMC         CMP         CMPSB       CMPSW       CWD         DAA
  1269.  DAS         DB          DD          DEC         DIV         DW
  1270.  EQU         HLT         IDIV        IMUL        IN          INC
  1271.  INT         INTO        IRET        JA          JAE         JB
  1272.  JBE         JC          JCXZ        JE          JG          JGE
  1273.  JL          JLE         JMP         JNA         JNAE        JNB
  1274.  JNBE        JNC         JNE         JNG         JNGE        JNL
  1275.  JNLE        JNO         JNP         JNS         JNZ         JO
  1276.  JP          JPE         JPO         JS          JZ          LAHF
  1277.  LDS         LEA         LES         LOCK        LODSB       LODSW
  1278.  LOOP        LOOPE       LOOPNE      LOOPNZ      LOOPZ       MOV
  1279.  MOVSB       MOVSW       MUL         NEG         NOP         NOT
  1280.  OR          OUT         POP         POPF        PUSH        PUSHF
  1281.  RCL         RCR         REP         REPE        REPNE       REPNZ
  1282.  REPZ        RET         RETF        ROL         ROR         SAHF
  1283.  SAL         SAR         SBB         SCASB       SCASW       SHL
  1284.  SHR         STC         STD         STI         STOSB       STOSW
  1285.  SUB         TEST        WAIT        XCHG        XLAT        XLATB
  1286.  XOR
  1287.  
  1288.  
  1289. The following conditional execution prefix is supported for
  1290. compatibility with Eric Isaacson's A86 assembler:
  1291.  
  1292.  IF
  1293.  
  1294.  
  1295. The following prefix is supported for inserting single or
  1296. multiple line Pascal statements within an assembly section.
  1297.  
  1298.  PAS
  1299.  
  1300.  
  1301. The following data definition and type qualifiers are supported:
  1302.  
  1303.  B           BYTE        W           WORD        D           DWORD
  1304.  BIT         BY          DUP         OFFSET      SEG DATA
  1305.  PROC        NEAR        F           FAR         ENDP
  1306.  
  1307.  
  1308. TP&Asm recognizes the following other assembly directives:
  1309.  
  1310.  ORG         RADIX       SEGMENT     ENDS        END
  1311.  
  1312.  
  1313. TP&Asm uses the standard set of register mnemonics:
  1314.  
  1315.  AL      BL      CL      DL      AH      BH      CH      DH
  1316.  AX      BX      CX      DX      SI      DI      BP      SP
  1317.  CS      DS      ES      SS
  1318.  
  1319.  
  1320. The following directives are unnecessary and are ignored:
  1321.  
  1322.  AT          COMMON      LABEL       MEMORY      PARA        STACK
  1323.  ASSUME      EXTRN       PAGE        PUBLIC      SUBTTL      TITLE
  1324.  PTR         SHORT       LONG
  1325.  
  1326. The following invalid string mnemonics should be replaced by the
  1327. five character versions specifying byte or word (CMPSB, MOVSW, etc):
  1328.  
  1329.  CMPS        LODS        MOVS        SCAS        STOS
  1330.  
  1331.  
  1332. TP&Asm does not currently support 8087 mnemonics or mnemonics
  1333. which are unique to a specific processor (80286, 80386, NEC, etc).
  1334. These mnemonics are reserved for upward compatibility to future
  1335. versions of TP&Asm, and cannot be used as Assembly data labels.
  1336.  
  1337. For compatibility with MASM, most assembly reserved words other than
  1338. prefixes and qualifiers can be used as code labels.
  1339.  
  1340. All reserved words can be used as Pascal symbols and referenced in
  1341. assembly language by prefixing the symbol with ">" or "<", or with
  1342. a valid UnitName or record qualifier, as discussed in the section
  1343. on General Assembler Syntax.
  1344.  
  1345.