home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / INLIN218.ZIP / INLINE.DOC < prev    next >
Encoding:
Text File  |  1988-03-05  |  15.0 KB  |  463 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.                                                      March 5, 1988
  9.  
  10.                                 INLINE ASSEMBLER
  11.                                   Version 2.18
  12.  
  13.  
  14.         OVERVIEW
  15.  
  16.         INLINE.EXE is an assembler designed to produce Inline 8086/8088 
  17.         and 8087 code for Turbo Pascal (tm) versions 3 and 4 programs.  
  18.         Like other assemblers, INLINE accepts as input an assembly 
  19.         language source file and produces an object file.  However, in 
  20.         this case, the 'object' file is an ASCII file consisting of 
  21.         Inline statements which may be inserted into the Turbo Pascal 
  22.         program.
  23.  
  24.         Figure 1 illustrates a Pascal function with Inline code generated 
  25.         by INLINE using the source file of Figure 2.
  26.  
  27.  
  28.         LOADING AND RUNNING INLINE
  29.  
  30.         First create an EXE file, INLINE.EXE, by compiling INLINE.PAS 
  31.         using version 4 of the Turbo Pascal compiler.  
  32.  
  33.         INLINE is called at the DOS prompt with two filename parameters 
  34.         specifying the names of the source and object files.  If no 
  35.         extensions are given, .ASM and .OBJ are used by default.  For 
  36.         instance,
  37.  
  38.           INLINE ABC DEF
  39.  
  40.         will cause INLINE to look for a source file, ABC.ASM, and create 
  41.         an object file, DEF.OBJ.  Files with no extension may be input or 
  42.         created by using a simple '.' for the extension.
  43.  
  44.         If the object filename is missing from the command line, an OBJ 
  45.         file will be created using the same name as the source file.  If 
  46.         neither filename is specified, then names will be requested once 
  47.         execution starts.
  48.  
  49.         Once execution begins, INLINE will run to completion with the 
  50.         only console output being error messages.
  51.  
  52.  
  53.         SYNTAX
  54.  
  55.         The appendix lists the mnemonics accepted by INLINE.  Syntax and 
  56.         mnemonics correspond to that used by most assemblers but note 
  57.         should be made of the following:
  58.  
  59.  
  60.  
  61.  
  62.                                    1
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.           1. Turbo Pascal symbols may be used within instruction entries 
  75.              by preceding the symbol with a '>' (16 bit symbol) or a '<' 
  76.              (8 bit symbol).  The characters '+' and '-' are considered 
  77.              part of the symbol.  This allows computations using symbols 
  78.              to be passed on to the compiler where the computation can be 
  79.              made.  For instance, in
  80.  
  81.                  MOV AX,[>SYMBOL+4]       ;'>SYMBOL+4' is passed on
  82.                  MOV AX,[BP+>SYMBOL+4]    ;again '>SYMBOL+4' is passed on
  83.                  MOV AX,>SYMBOL+4[BP]     ;also acceptable
  84.  
  85.              Note that
  86.  
  87.                  MOV AX,[>SYMBOL+4+BP]
  88.  
  89.              is not correct since the wrong instruction will be generated 
  90.              and '>SYMBOL+4+BP' will be passed on.
  91.  
  92.           2. Labels (for use with jump instructions) may be defined 
  93.              simply by appending a ':' to the first item on a line.  
  94.              Avoid using CS:, DS:, ES:, and SS: as labels, as these 
  95.              specify segment overrides.
  96.  
  97.           3. Numerical entries are assumed to be decimal unless preceded 
  98.              by a '$' indicating a hexadecimal entry.  Characters within 
  99.              single quotes may be used for numerical entries as:
  100.  
  101.                  CMP AL,'a'
  102.  
  103.           4. Square brackets are used to indicate 'contents of'.  If no 
  104.              square brackets are used, an immediate operand is assumed.
  105.  
  106.                  MOV AX,[>DATA]  ;Load AX with the contents of DATA.
  107.                  MOV AX,>DATA    ;Load AX with DATA.
  108.  
  109.           5. Instruction prefixes and segment override prefixes may 
  110.              precede the instruction on the same line or may be included 
  111.              on a previous line.  A colon is optional after the segment 
  112.              prefix.
  113.  
  114.                  ES: MOV AX,[1234]    ;ok
  115.                  REPNE MOVSB          ;ok
  116.                  MOV AX,ES:[1234]     ;incorrect syntax for INLINE
  117.  
  118.           6. Comments may be included in the source.  They are delimited 
  119.              by a ';'.
  120.  
  121.           7. Instructions which don't clearly specify the data size 
  122.              require that BYTE PTR, WORD PTR, DWORD PTR, QWORD PTR, or 
  123.              TBYTE PTR be used.  These may be abbreviated by using the 
  124.              first two letters.
  125.  
  126.  
  127.  
  128.                                    2
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.                  INC BYTE PTR [>BDATA]
  141.                  DEC WO >WARRAY[DI]
  142.                  FLD QWORD [>DBL_REAL]
  143.  
  144.           8. JMP instructions may use SHORT, NEAR, or FAR (they should 
  145.              not be abbreviated).  In the absence of one of these words, 
  146.              a SHORT jump will be encoded if the label is already defined 
  147.              and is within range.  If the label is not defined, a NEAR 
  148.              JMP will be encoded unless SHORT is used.
  149.  
  150.              A FAR CALL or JMP may be made to a direct address by stating 
  151.              both the segment and offset separated by a colon.
  152.  
  153.                  CALL FAR $1234:$5678
  154.  
  155.              For Turbo Version 3 only, direct CALL's or JMP's may be made 
  156.              to other Turbo procedures and functions using symbolic 
  157.              names.  The '*' location counter reference is required (not 
  158.              available in version 4) to allow Turbo to determine the 
  159.              correct displacement, as:
  160.  
  161.                  CALL >PROCNAME-*-2
  162.  
  163.              Null JMP's which may be required for delay between port 
  164.              calls on the 80286, may be made as;
  165.  
  166.                  JMP >0        ;or
  167.                  JMP SHORT <0
  168.  
  169.         Normally INLINE generates only one Inline statement per source 
  170.         file.  However, the 'NEW' pseudo-instruction may be used to 
  171.         terminate one Inline statement and begin another.  Using the NEW 
  172.         instruction, it is possible to create a number of Inline 
  173.         statements from one source file.
  174.  
  175.  
  176.         FLOATING POINT INSTRUCTIONS
  177.  
  178.         An automatic WAIT (FWAIT) opcode is generated for each floating 
  179.         point instruction except for the 'no wait' instructions (those 
  180.         with 'N' for the second letter.  However, the WAIT instruction 
  181.         may be required before a floating point instruction having a 
  182.         segment override to insure the WAIT is properly positioned.
  183.  
  184.                WAIT
  185.                ES:FMUL DWORD [BX]
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.                                    3
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.         CAVEATS
  207.  
  208.         INLINE has no way of knowing the value of any symbols used so the 
  209.         user should be especially careful when using the '<' byte size 
  210.         specifier.  A case in point is when referring to stack variables, 
  211.         as:
  212.  
  213.              MOV AX,<ABC[BP]    or
  214.              MOV AX,>ABC[BP]
  215.  
  216.         The use of '<' here will result in saving one byte but will only 
  217.         work correctly if ABC is in the range -128 to 127.  Stack offsets 
  218.         often exceed this in Turbo 4, so it is much safer to use  '>'.
  219.  
  220.         Note that just because a constant is byte size does not make it 
  221.         safe to use '<'.  If ABC were defined as =255, then CMP BX,<ABC 
  222.         would not assemble correctly as a constant in the range -128 to 
  223.         127 would be expected.  Here again, it's safer to use '>'.
  224.  
  225.         Many instructions may be correctly assembled in more than one 
  226.         way.  This has caused some confusion in the past when INLINE 
  227.         produce a byte sequence different from that expected.  When in 
  228.         doubt, check the byte sequence out using DEBUG or run it through 
  229.         UNINLINE for verification.
  230.  
  231.  
  232.         RESTRICTIONS
  233.  
  234.         The object file is limited to 32k.  This includes comments and 
  235.         spaces.
  236.  
  237.         Symbols (including any addons from + and -) are limited to 32 
  238.         characters.
  239.  
  240.         Labels may be used in jump statements only and not as data 
  241.         references.  While there is a DB pseudo-opcode, it is not very 
  242.         useful with this restriction.
  243.  
  244.         The number of statement labels that may be defined is limited 
  245.         only by the heap space available.
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.                                    4
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.         VERSIONS
  273.  
  274.         2.00 Added 8087 instructions.
  275.         2.01 Fixed bug which wiped out INT $A vector.
  276.         2.02 Fixed bug which prevented labels from starting with BY, WO, 
  277.              DW, QW, and TB.
  278.         2.1  Add NEW pseudo-instruction.  Fixed bug which occurred with 
  279.              filenames having no extension.  Other bugs fixed, notably 
  280.              those effecting IN and OUT.
  281.         2.11 Calculate restricted range for short jumps correctly.
  282.              Fix bug so CALL/JMP <register> may be used.
  283.         2.12 Allow CALL and JMP direct instructions.
  284.         2.13 Allow JMP >0 and JMP SHORT <0 for null JMP's.
  285.         2.14 Change output format to better sync with TMAP's line 
  286.              numbers.
  287.         2.15 Fix 'shl cl,1' which assembled as shl cl,cl
  288.         2.16 Change byte size check in MemReg so the likes of
  289.                      MOV [DI+$FE],AX will assemble right.
  290.              Allow ',' in DB pseudo op instruction.
  291.         2.17 Convert source to Turbo 4.
  292.         2.18 Implement the sign extension bit for some instructions
  293.  
  294.  
  295.         (C) Copyright 1985,86,87 by L. David Baldwin.
  296.  
  297.         INLINE may be copied and distributed freely providing that no fee 
  298.         is charged and it is not part of a package for which a charge is 
  299.         made.
  300.  
  301.         Please report all bugs, suggestions, and problems to Dave 
  302.         Baldwin, CompuServe ID #76327,53.
  303.  
  304.              22 Fox Den Rd., (Summer)     144 13th St. East,  (Winter)
  305.              Hollis, NH 03049             Tierra Verde, FL 33715
  306.              (603) 465-7857               (813) 867-3030
  307.  
  308.  
  309.              Turbo Pascal is a trademark of Borland International Inc.
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.                                    5
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.  
  338.         FUNCTION Scan(Limit :Integer; Ch :Char; Var T ): Integer;
  339.          {Scan Limit characters for Ch. Return the number of characters
  340.           skipped to find a match.  If not found, return result=Limit.
  341.           Limit may be negative for a backwards scan.}
  342.         Var
  343.           Rslt : Integer;
  344.         begin
  345.         Inline(
  346.           $FC/             {    cld              ;assume forward}
  347.           $8A/$86/>CH/     {    mov al,>Ch[bp]   ;char to search for}
  348.           $8B/$8E/>LIMIT/  {    mov cx,>Limit[bp];bytes to search}
  349.           $09/$C9/         {    or cx,cx         ;check sign}
  350.           $9C/             {    pushf            ;save flags}
  351.           $79/$03/         {      jns x1}
  352.           $F7/$D9/         {    neg cx           ;make positive}
  353.           $FD/             {    std              ;but search in reverse}
  354.           $89/$CA/         {x1: mov dx,cx        ;save full count}
  355.           $C4/$BE/>T/      {    les di,>T[bp]    ;ptr to start}
  356.           $F2/$AE/         {    repne scasb      ;search}
  357.           $75/$01/         {      jne x2}
  358.           $41/             {    inc cx           ;found a match}
  359.           $29/$CA/         {x2: sub dx,cx        ;find count to match}
  360.           $9D/             {    popf}
  361.           $79/$02/         {      jns x3}
  362.           $F7/$DA/         {    neg dx           ;make negative if reverse}
  363.           $89/$96/>RSLT);  {x3: mov >Rslt[bp],dx ;put in function result}
  364.         Scan := Rslt;
  365.         end;
  366.  
  367.                            Figure 1: Pascal Function using Inline Code
  368.  
  369.             cld              ;assume forward
  370.             mov al,>Ch[bp]   ;char to search for
  371.             mov cx,>Limit[bp];bytes to search
  372.             or cx,cx         ;check sign
  373.             pushf            ;save flags
  374.               jns x1
  375.             neg cx           ;make positive
  376.             std              ;but search in reverse
  377.         x1: mov dx,cx        ;save full count
  378.             les di,>T[bp]    ;ptr to start
  379.             repne scasb      ;search
  380.               jne x2
  381.             inc cx           ;found a match
  382.         x2: sub dx,cx        ;find count to match
  383.             popf
  384.               jns x3
  385.             neg dx           ;make negative if reverse
  386.         x3: mov >Rslt[bp],dx ;put in function result
  387.  
  388.                           Figure 2:  INLINE Input File
  389.  
  390.  
  391.  
  392.                                    6
  393.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403.  
  404.         APPENDIX
  405.  
  406.           8086/8088 Opcode Mnemonics Recognized by INLINE
  407.  
  408.                 AAA       HLT       JNE       LOOPNZ    ROR    
  409.                 AAD       IDIV      JNG       LOOPZ     SAHF   
  410.                 AAM       IMUL      JNGE      MOV       SAL    
  411.                 AAS       IN        JNL       MOVSB     SAR    
  412.                 ADC       INC       JNLE      MOVSW     SBB    
  413.                 ADD       INT       JNO       MUL       SCASB  
  414.                 AND       INTO      JNP       NEG       SCASW  
  415.                 CALL      IRET      JNS       NOP       SHL    
  416.                 CBW       JA        JNZ       NOT       SHR    
  417.                 CLC       JAE       JO        OR        SS     
  418.                 CLD       JB        JP        OUT       STC    
  419.                 CLI       JBE       JPE       POP       STD    
  420.                 CMC       JC        JPO       POPF      STI    
  421.                 CMP       JCXZ      JS        PUSH      STOSB  
  422.                 CMPSB     JE        JZ        PUSHF     STOSW  
  423.                 CMPSW     JG        LAHF      RCL       SUB    
  424.                 CS        JGE       LDS       RCR       TEST   
  425.                 CWD       JL        LEA       REP       WAIT   
  426.                 DAA       JLE       LES       REPE      XCHG   
  427.                 DAS       JMP       LOCK      REPNE     XLAT   
  428.                 DB        JNA       LODSB     REPNZ     XOR    
  429.                 DEC       JNAE      LODSW     REPZ   
  430.                 DIV       JNB       LOOP      RET    
  431.                 DS        JNBE      LOOPE     RETF   
  432.                 ES        JNC       LOOPNE    ROL    
  433.  
  434.  
  435.           8087 Opcode Mnemonics Recognized by INLINE
  436.  
  437.                 F2XM1     FDIVRP    FLD       FNOP      FSTP   
  438.                 FABS      FENI      FLD1      FNSAVE    FSTSW  
  439.                 FADD      FFREE     FLDCW     FNSTCW    FSUB   
  440.                 FADDP     FIADD     FLDENV    FNSTENV   FSUBP  
  441.                 FBLD      FICOM     FLDL2E    FNSTSW    FSUBR  
  442.                 FBSTP     FICOMP    FLDL2T    FPATAN    FSUBRP 
  443.                 FCHS      FIDIV     FLDLG2    FPREM     FTST   
  444.                 FCLEX     FIDIVR    FLDLN2    FPTAN     FXAM   
  445.                 FCOM      FILD      FLDPI     FRNDINT   FXCH   
  446.                 FCOMP     FIMUL     FLDZ      FRSTOR    FXTRACT
  447.                 FCOMPP    FINCSTP   FMUL      FSAVE     FYL2X  
  448.                 FDECSTP   FINIT     FMULP     FSCALE    FYL2XP1
  449.                 FDISI     FIST      FNCLEX    FSQRT     FWAIT  
  450.                 FDIV      FISTP     FNDISI    FST    
  451.                 FDIVP     FISUB     FNENI     FSTCW  
  452.                 FDIVR     FISUBR    FNINIT    FSTENV 
  453.  
  454.  
  455.  
  456.  
  457.  
  458.                                    7
  459.  
  460.  
  461.  
  462.  
  463.