home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / asmutil / a86v322.zip / A03.DOC < prev    next >
Text File  |  1990-01-21  |  16KB  |  349 lines

  1. CHAPTER 3   OPERATION AND REQUIREMENTS
  2.  
  3.  
  4. Creating Programs to Assemble
  5.  
  6. Before you invoke A86 you must have an assembly-language source
  7. program to assemble.  A source program is an ASCII text file,
  8. created with the text editor of your choice.  The editor must
  9. produce a file that is free of internal records known only to the
  10. editor.  Some of the fancier word processors will require you to
  11. use a "plain text" mode to insure that the file is free of such
  12. records.
  13.  
  14. This manual will fully explain to you the correct syntax of an
  15. A86 program, but it is not intended to teach you about the
  16. 86-family instruction set, or about assembly-language interfacing
  17. to your computer or your operating system.
  18.  
  19. The instruction set charts in Chapters 6 and 7 give concise,
  20. one-line descriptions of each instruction, but they don't go into
  21. any detail about instruction usage.  For such detail, I recommend
  22. either one of the two books The 8086/8088 Primer by Stephen P.
  23. Morse, or The 80286 Architecture by Morse and Albert.  The latter
  24. book covers the 8087/287 and is recommended if you have a
  25. floating-point coprocessor, or if you wish to explore the
  26. expanded capabilities of the 286.  (My 386 book is the latest in
  27. a series in which those two books are predecessors.)
  28.  
  29. To learn how to make system calls to input from keyboard or disk,
  30. output to screen, printer or disk, etc., you need a book that
  31. covers the MS-DOS operating system and the BIOS for the IBM-PC,
  32. or whatever computer you have if it's non-IBM-BIOS-compatible (if
  33. you don't know whether or not it's compatible, it probably is).
  34. I used Peter Norton's Programmer's Guide to the IBM-PC.  If
  35. you're less familiar with assembly language, you will probably
  36. want his Assembly Language Guide to the IBM-PC instead.
  37.  
  38.  
  39. Program Invocation
  40.  
  41. To invoke A86, you must provide a program invocation line, either
  42. typed to the console when the DOS command prompt appears, or
  43. included in a batch file.  The program invocation line consists
  44. of the following:
  45.  
  46. 1. The program name A86.
  47.  
  48. 2. The names of the source files you want to assemble.  You may
  49.    use the wild card delimiters * and ? if you wish, to denote a
  50.    group of source files to be assembled.  A86 will sort all
  51.    matching names into alphabetical order for each wild card
  52.    specification; so the files will be assembled in the same
  53.    order even if they get jumbled up within a directory.
  54.  
  55.    A86 identifies the end of the source file names when it sees a
  56.    name with no extension, or a name with the default object
  57.    extension (COM, BIN or OBJ, as described shortly).  Sorry, you
  58.    cannot have a source file with the default object extension.
  59.                                                               3-2
  60.  
  61. 3. You may optionally provide the word TO, to separate the source
  62.    file names from the output file names.
  63.  
  64. 4. The name of the output program.  If you do not provide an
  65.    extension, A86 will assume one of the following extensions:
  66.  
  67.    a. .OBJ if you invoked the +O switch, for linkable object file
  68.       production.
  69.  
  70.    b. .BIN if there is no +O switch, but there is an ORG 0 in
  71.       your program.
  72.  
  73.    c. .COM otherwise.
  74.  
  75.    If you want your program file to have no extension, you end
  76.    the file name with a period.
  77.  
  78.    You have the option to omit both the program file name and the
  79.    symbol table file name from the invocation.  If you do so, A86
  80.    will output the program source.COM (or source.OBJ or
  81.    source.BIN) and the symbol table source.SYM; where "source" is
  82.    a name derived from the list of source files, according to the
  83.    rules described in the section "Strategies for Source File
  84.    Maintenance" later in this chapter.
  85.  
  86. 5. The name of the symbol table file.  You do not need to give
  87.    the .SYM extension: A86 will produce a file with extension
  88.    .SYM in any case.  In earlier versions of A86 I had allowed
  89.    other extensions to be specified, but this meant that by
  90.    carelessly permuting names on the command line, you could
  91.    destroy a source file-- not good!
  92.  
  93.    You can omit the name of the symbol table file. If you do so,
  94.    A86 will use the same root as the output program name.  If you
  95.    desire no symbol table file, specify the +S switch in your
  96.    invocation line or A86 environment variable (described later
  97.    in this chapter).
  98.  
  99.  
  100. Assembler Switches
  101.  
  102. In addition to input and output file names, you may intersperse
  103. assembler switch settings anywhere after the A86 program name.
  104. They are all acted upon immediately, no matter where they are on
  105. the command line.  Some of the switches are discussed in more
  106. detail elsewhere; I'll summarize them here:
  107.  
  108. +C  causes the assembler to output symbol names with lower case
  109.     letters to its OBJ and SYM files.  The case of letters is
  110.     still ignored during assembly.  I output the name as it
  111.     appears in the last PUBLIC or EXTRN directive containing it;
  112.     if there is no such directive, I use the first occurrence of
  113.     the symbol to control which letters are output lower case.
  114.     (+C duplicates Microsoft MASM's /mx switch.)
  115.                                                               3-3
  116.  
  117. +c  causes the assembler to consider the case of letters within
  118.     all non-built-in symbols as significant both during assembly
  119.     and for output.  Thus, for example, you can define different
  120.     symbols X and x.  (+c duplicates MASM's /ml switch.)
  121.  
  122. +D  causes the default base for numeric constants to be decimal,
  123.     even if the constants have leading zeroes.
  124.  
  125. -D  causes the default base to be hexadecimal if there is a
  126.     leading zero; decimal otherwise.
  127.  
  128. +E  causes the error-message-augmented source file to be written
  129.     to yourname.ERR within the current directory, in all cases.
  130.     With +E, A86 will never rewrite your original source file.
  131.  
  132. -E  causes A86 to insert error messages into your source file,
  133.     whenever the file is in the current directory.  If the file
  134.     is not in the current directory, A86 write an ERR file no
  135.     matter what the E switch setting is.
  136.  
  137. +F  causes A86 to generate the 287 form of floating point
  138.     instructions (no implicit FWAIT bytes are generated before
  139.     the instructions).  This mode can also be specified in the
  140.     program with the .287 directive.
  141.  
  142. +f  causes A86 to support emulation of the 8087.  When A86 sees a
  143.     floating point instruction, it generates external references
  144.     to be resolved by the standard emulation library (provided by
  145.     Microsoft, Borland, etc.).  When you LINK your program to the
  146.     emulation library, the floating point instructions are
  147.     emulated by software.  NOTE you must be assembling to a
  148.     linkable OBJ file for this mode to have effect; otherwise, +f
  149.     is ignored.
  150.  
  151. -F  causes emulation and default-287 to be disabled.  You'll
  152.     still get 287 generation if there is a .287 directive in your
  153.     program.
  154.  
  155. +Ln  causes A86 to implement one or more of the following minor
  156.     options for code-generation.  All these options enhance MASM
  157.     compatibility.  The first three do so at the expense of
  158.     program size.  The number n should be the sum of the numbers
  159.     for each of the options selected.  For example, +L10 will
  160.     select the options numbered 2 and 8.
  161.  
  162.     1 causes A86 to generate a longer (3-byte) instruction form
  163.         for an unconditional JMP instruction to a forward
  164.         reference local label, e.g. JMP >L1.  A86 normally
  165.         assumes that since it's a local label, it will be nearby
  166.         and the short, 2-byte form will work.  With this option
  167.         your code will usually be longer than necessary, but
  168.         you'll be spared having to occasionally go back and code
  169.         an explicit JMP LONG >L1.
  170.  
  171.     2 causes A86 to refrain from optimizing the LEA instruction.
  172.         Without this option A86 will replace an LEA with a
  173.         shorter, equivalent MOV when it sees the chance.
  174.                                                               3-4
  175.  
  176.     4 causes A86 to generate a slightly more inefficient internal
  177.         format for memory references within an OBJ file.  The
  178.         Power C compiler's MIX utility requires the inefficient
  179.         form. The makers of Power C refused to support their
  180.         customers on this by enhancing MIX, so I am forced to
  181.         offer this option.
  182.  
  183.     8 causes A86 to assume that all ambiguous forward reference
  184.         operands to instructions other than jumps or calls refer
  185.         to memory variables and not offsets or constant values.
  186.         You can override this on a one-by-one basis, with the
  187.         OFFSET operator.
  188.  
  189. -L  causes A86 to revert to its default for all the above
  190. options.
  191.  
  192. +O  causes A86 to produce a linkable .OBJ file when the output
  193.     file name extension is not explicitly given.
  194.  
  195. -O  causes A86 to produce an executable .COM file when the output
  196.     file name extension is not explicitly given.
  197.  
  198. +S  suppresses the creation of the symbol table (.SYM) file in
  199.     normal (no errors) assembly.  This is overridden if you give
  200.     an explicit symbols file name in the invocation line.
  201.  
  202. -S  causes the symbol table file to be created in all cases.
  203.  
  204. +X  causes A86 to require that undefined names be explicitly
  205.     declared with an EXTRN when A86 is producing a linkable .OBJ
  206.     file.  The X switch has no effect when A86 is making a .COM
  207.     file.
  208.  
  209. -X  causes A86 to quietly assume that all undefined names are
  210.     valid external references.
  211.  
  212. The default setting for all the switches is "minus".  Multiple
  213. switches can be specified with a single sign; e.g. +OX is the
  214. same as +O+X.
  215.  
  216.  
  217.  
  218. The A86 Environment Variable
  219.  
  220. To allow you to customize A86, the assembler examines the MS-DOS
  221. environment variable named "A86" when it is invoked.  If there is
  222. such a variable, its contents are inserted before the invocation
  223. command tail, as if you had typed them yourself.
  224.  
  225. For example, if you execute the command SET A86=+OX while in DOS
  226. (typically in the AUTOEXEC.BAT file run when the computer is
  227. started), then the O and X switches will be "plus", unless
  228. overridden with a "minus" setting in the command line.
  229.                                                               3-5
  230.  
  231. You may also include one or more file names in the A86
  232. environment variable.  Those files will always be assembled
  233. first, before the files you specify on the command line.  This
  234. allows you to set up a library of macro definitions, which will
  235. always be automatically available to your programs.  Thus, for
  236. example, the DOS command  SET A86=C:\A86\MACDEF.8 +OX  will cause
  237. both the O and X switches to default ON, but will also cause the
  238. file MACDEF.8 of subdirectory A86 of drive C to always be
  239. assembled.
  240.  
  241.  
  242. Using Standard Input as a Command Tail
  243.  
  244. The following feature is a bit advanced.  If you're not familiar
  245. with the practice of redirecting standard input, you may safely
  246. skip this section.
  247.  
  248. A86 can also be configured to take its command arguments from
  249. standard input, in addition to the invocation command tail or the
  250. A86 environment variable.  This allows A86 to be used in those
  251. menu-driven systems that don't generate command tails for
  252. programs.  It also allows other programs to create lists of files
  253. to be assembled, then "pipe" the list to A86.
  254.  
  255. Here's how the feature works: when the command argument A86 is an
  256. ampersand &, A86 will prompt for standard input.  If the
  257. ampersand is seen but there are other things following it, the
  258. ampersand is ignored.
  259.  
  260. For example, you can place a list of file names and switch
  261. settings into a file called FILELIST.  You can then invoke the
  262. assembler via
  263.  
  264. A86 <FILELIST &
  265.  
  266. which will cause the contents of the FILELIST file to be used as
  267. a command line.
  268.  
  269. You may place an ampersand at the end of your A86 environment
  270. variable.  If you do so, then A86 will prompt for file names
  271. whenever it is invoked without any command arguments (you type
  272. A86 followed immediately by the ENTER key to the MS-DOS prompt).
  273. This is the mode used if you have a menu system that can't
  274. generate an invocation command tail.
  275.  
  276. Note: when you redirect standard input so that it comes from a
  277. file, A86 will read all the lines of the file (up to a limit of
  278. 1023 bytes), and substitute spaces for the line breaks.  Thus you
  279. may give the file names on individual lines, for readability.
  280. However, if the feature is invoked manually (no redirection), so
  281. that you are typing in the line after the prompt, A86 will take
  282. the first line only.  You need to give all your switches and
  283. files on that one line.
  284.                                                               3-6
  285.  
  286. Strategies for Source File Maintenance
  287.  
  288. A86 encourages modular programming, by letting you break your
  289. source into separate files, with complete impunity.  A86 has no
  290. concern whatsoever for file breaks-- it treats the sequence of
  291. files as a single source code stream.
  292.  
  293. You should consider one or more of the following strategies,
  294. which I have adopted in my source file management:
  295.  
  296. 1. I name all my A86 source files with the same extension, which
  297.    is found on no other files. The particular extension I have
  298.    chosen is ".8". I did not choose the more common .ASM, because
  299.    I have a few source files designed for MSDOS's assembler.  If
  300.    you don't like .8, I would suggest .A86.
  301.  
  302. 2. I keep a separate subdirectory on my hard disk for each
  303.    multi-source-file A86 program I have.  Then the simple command
  304.    "A86 *.8" performs the assembly for the current directory's
  305.    program.
  306.  
  307. 3. I exploit the fact that A86 expands wild cards into
  308.    alphabetical order.  Whenever I want a source file to be
  309.    assembled first (e.g., when it contains variable
  310.    declarations), I append a decimal digit to the start of the
  311.    file name: 0 for the first file, 1 for the second, etc., for
  312.    however many files that need to be explicitly ordered.  If a
  313.    file needs to come last, I append a "Z" to the start of the
  314.    file name.
  315.  
  316.    To accommodate this strategy, I have programmed A86 to a
  317.    somewhat complicated algorithm for determining the default
  318.    output file name.  I use the name of the first source file;
  319.    but I truncate the first character if it is a decimal digit.
  320.    However, you may have a general-purpose file that must come
  321.    first; so I have provided the following exception: if you have
  322.    a source file whose name begins with the digit "9", that name
  323.    (without the 9) is used.  If you don't like this, you can
  324.    always explicitly give the program name you want: "A86 *.8
  325.    MYPROG".
  326.  
  327.  
  328. System Requirements for A86
  329.  
  330. A86 requires MS-DOS V2.00 or later.  No BIOS or lower-level calls
  331. are made by A86, so A86 should run on any MS-DOS machine.  Please
  332. let me know if you find this not to be the case.
  333.  
  334. A86 itself is a small program, and it is fairly flexible about
  335. the memory it uses.  You can assemble small files with only 32K
  336. bytes of memory beyond the program itself, which in the current
  337. version is under 22K bytes-- a total of 54K bytes beyond the
  338. operating system. The more memory you have, the more capacity A86
  339. has, in symbol table size, source file size, and output file
  340. size.  If it can, A86 will use up to 256K bytes of memory.
  341.                                                               3-7
  342.  
  343. As I just noted, in a small-memory system A86 severely limits the
  344. size of source files.  But remember that this doesn't hurt you
  345. badly: you can split up source files with impunity.  A86
  346. assembles a sequence of files as if it were a single source
  347. stream (similar to the INCLUDE facility of other assemblers).
  348.  
  349.