home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 13 / CDA13.ISO / cdactual / demobin / share / program / Asm / AMSCLS.ZIP / AMSCLS.DOC next >
Encoding:
Text File  |  1991-06-09  |  16.4 KB  |  555 lines

  1.  
  2.  
  3.               "A-MACROS"
  4.  Control Logic Structure Macros for MASM
  5.                 Ver.2.10
  6.       written by Hortens S. Endoh
  7.         06/Jun/1986 17/Jul/1987
  8.                13/Feb/1991
  9.  
  10.   Copyright (C) Jun.1986 Hortense S. Endoh
  11.  
  12. --------------------------------------------
  13.  
  14.        Modified by H.Yoshizaki for
  15.      correcting conditional $_break
  16.         and optimizing $_until.
  17.                11/Feb/1991
  18.  
  19. --------------------------------------------
  20.  
  21. 1. AMSCLS. BRIEF HISTORY
  22. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  23.  This Assembler Macro set is an include file for Microsoft's Macro 
  24.  Assembler MASM to write control structures easier in source code.
  25.  The first part of it appeared originally on October issue of a Japanese 
  26.  Computer Magazine ASCII as a series of articles. 
  27.  Mr.Takuya Nishimura has succeeded the article after November. Later, the 
  28.  Macro-set was sold as a part of Disk Service from ASCII Cooperation with
  29.  the title "Assembler Macro-Programming Techniques/A-MACROS".
  30.    This Macro Set is a minor version ups of the version originally in
  31.  the Disk version, and the speed of assembling is improved 40 to 50 percent
  32.  less than the time needed in the original version.
  33.    The Original Disk service from ASCII has almost sold out recently.
  34.  We have heard frequent requests for the reproduction and told by many
  35.  people that the MACRO set has been used continuously. Hence we have
  36.  made a negotiation with ASCII cooperation so that we may distribute the
  37.  package as a free-ware from January 1991. Two macros $_ldptr and $_stptr
  38.  are contributed by Mr.T.Nishmura.
  39.  
  40.    After ver 2.01a, the macro set is revised by Haruyasu Yoshizaki
  41.  for the bugs in the codes generated by $_break blknm,stmt,cnd Macros,
  42.  and the routine for $_until is optimized.
  43.  
  44.  
  45.  
  46. 2. Environments.
  47.    ~~~~~~~~~~~~~
  48.  This Macro-set is supported for MSDOS ver 2.11 or later with MASM ver 1.27.
  49.  We recommend you to use it with MASM ver 5.1 for we has made an extensive
  50.  tests with this version. If you are familiar with OPTASM from SLR Co.,
  51.  then you had better use the macro-set with it. We are quite sure that
  52.  this set will work well with all the versions of OPTASM. There should be no
  53.  conflicts with TASM from Borland International, though if anything wrong
  54.  should happen with TASM please let us know. PASM from Phoenix Co. is not
  55.  compatible with our Macro package.
  56.  
  57.  To use the control structure in you program, please include the set
  58.  near the top of your source code.
  59.  
  60.         include    amscls.inc            This is where you include.
  61.         $_init GEN                       Initialize Macro Set.
  62.         :
  63.         :
  64. code    segment
  65.         assume    cs:code
  66.         org    0100h
  67.         :
  68.         :
  69.         $_for <mov AX, 1>, <<cmp AX, 255>, LE>, <inc AX>   Macro is used here.
  70.             $_if <cmp CH, 2>, E                                
  71.                 mov    CH, 0
  72.             $_else
  73.                 $_if <cmp CH, 4>, E
  74.                     mov    CL, test_data[BX]
  75.                     mov    CH, 08h
  76.                 $_endif
  77.             $_endif
  78.             :
  79.         $_enddo
  80.         :
  81.         :
  82. code    ends
  83.         end
  84.  
  85.  
  86. 3. Usage and Definitions.
  87.    ~~~~~~~~~~~~~~~~~~~~~~
  88.  
  89.  We have carefully designed that the macro package should not generate any
  90.  unexpected codes in your objects. You will have no difficulty understanding
  91.  the control structures. The examples are self-explanatory we hope.
  92.  
  93.  Here begins the description of each Control Structures.
  94.  
  95.  
  96.  $_INIT Initialize.
  97.  ==================
  98.  
  99.  SYNTAX:
  100.  
  101.     $_init [ GEN ] [, { COM| NEAR | FAR } ]
  102.  
  103.  SUMMARY:  You must first call this routine before you use any macro 
  104.  -------   in the set. The first parameter 'GEN' if specified, you will 
  105.            get expanded listfile. The second parameter is to specify 
  106.            models. The default is 'NEAR'. You don't need to specify any
  107.            if you are calling this macro set in a block.
  108.  
  109.  NOTE:     ALL the parameters must be specified in UPPER_CASE.
  110.  -----
  111.  
  112.  
  113.  
  114.  $_IF,  $_C, $_ENDIF conditional branch.
  115.  =======================================
  116.  
  117.  SYNTAX:
  118.  ------               
  119.  
  120.     $_if  condition_1
  121.     [ $_c condition_2 ]
  122.           :
  123.     [ $_c condition_n ]
  124.           :
  125.     [ $_else ]
  126.           :
  127.     $_endif
  128.  
  129.   SUMMARY:    Checks each condition associated with an $_if and $_c
  130.   --------    directive until a true (nonzero) expression is
  131.               found, then processes the : <text-block> associated with
  132.               that test expression. If there is a $_else clause, the
  133.               : <text-block> associated with it is processed only if no
  134.               test expression in the $_if clauses has a nonzero
  135.               value. $_c is the combined condition directive.
  136.  
  137.  
  138.   EXAMPLE:
  139.   --------
  140.  
  141.     $_if <cmp flag, 0>, E, AND
  142.     $_c <cmp AX, 0>, L
  143.         neg    AX
  144.         mov    flag, 1
  145.     $_else
  146.         mov    flag, 0
  147.     $_endif
  148.  
  149.  
  150.  $_WHILE repeating block structure 1.
  151.  ====================================
  152.  
  153.  SYNTAX:
  154.  -------
  155.     $_while condition_1  [ ,block ]
  156.       [ $_c condition_2 ]
  157.          :
  158.       [ $_c condition_n ] 
  159.          :
  160.          [ $_break [ block ] ]
  161.          :
  162.     $_enddo
  163.   
  164.   SUMMARY:   Execute block repeatedly until condition_1 etc
  165.   -------    become false. If the condition_s are not true
  166.              the control moves to the line after $_enddo.
  167.              By using $_break macro, you may exit from the block.
  168.  
  169.   
  170.   EXAMPLE:
  171.   -------
  172.     mov    CX, 100
  173.     $_while <cmp CX, 1>, GE
  174.         mov    tbl[BX], word ptr 0
  175.         $_if <cmp BX, 8000h>, GE
  176.             xor   BX, BX
  177.             $_break
  178.         $_endif
  179.         inc    BX
  180.         inc    BX
  181.         dec    CX
  182.     $_enddo
  183.  
  184.   NOTE:  Please note the following example is an endless loop, 
  185.   ----   less you should use $_break exit.
  186.  
  187.     $_while <TRUE>
  188.            :
  189.            :
  190.         $_if <cmp AX, 1>, E
  191.             $_break
  192.         $_endif
  193.            :
  194.     $_enddo
  195.  
  196.  
  197.   $_DO repeating block 2.
  198.   ======================  
  199.    SYNTAX:
  200.    --------
  201.  
  202.     $_do [ block ] 
  203.                 :
  204.                [$_break [ block ]]
  205.                 :
  206.                 :
  207.     $_until condition_1 [ , block ]
  208.       [ $_c condition_2 ]
  209.        :
  210.       [ $_c condition_n ]
  211.  
  212.    SUMMARY: $_until structure checks the exit condition from the loop 
  213.    -------  at the end, and hence the loop is executed at least once. 
  214.             $_break enables exiting from the block.
  215.  
  216.  EXAMPLE:
  217.  -------
  218.     mov    BX, 0
  219.     $_do
  220.         mov    AL, tbl[BX]
  221.         $_if <cmp AL, 00h>, E
  222.             $_break
  223.         $_endif
  224.         inc    BX
  225.     $_until <cmp BX, 100h>, GE
  226.  
  227.  NOTE: As a condition any one of the following directives
  228.  ----  may be specified. LOOP,LOOPE,LOOPNE,LOOPNZ,LOOPZ.
  229.  
  230.  
  231.     mov   CX, 32
  232.     $_do
  233.          :
  234.          :
  235.     $_until <LOOP>
  236.  
  237.  NOTE:  Next example shows a loop executed only once. Jump to the preceding
  238.  -----  block may be expressed by this way. There is no essential difference
  239.         with simple Jumps.
  240.  
  241.     $_do
  242.            :
  243.            :
  244.         $_if <cmp AX, 255>, E
  245.             $_break
  246.         $_endif
  247.            :
  248.     $_enddo
  249.  
  250.  
  251.  $_FOR repeating structure 3.
  252.  ============================
  253.  
  254.   SYNTAX:
  255.   -------
  256.      $_ for <init-expr>, <cond-expr>, <loop-expr> [,block ] 
  257.             :
  258.             :
  259.           [ $_break [ block ] ]
  260.             :
  261.      { $_endfor | $_enddo }
  262.         
  263.  SUMMARY: Same as ' for' in C.   Executes <statement> repeatedly. 
  264.  -------- First, the initialization (<init-expr>) is evaluated. 
  265.           Then, while the conditional expression (<cond-expr>) consisting
  266.           of command directive pair, holds true, <statement> is executed 
  267.           and the loop expression (<loop-expr>) is evaluated. 
  268.           When <cond-expr> become false, control passes to the statement 
  269.           following the $_endfor or $_enddo.
  270.  
  271.  EXAMPLE:
  272.  --------
  273.     $_for <mov AX, 1>, <<cmp AX, 255>, LE>, <inc AX>
  274.         $_if <cmp CH, 2>, E
  275.             mov    CH, 0
  276.         $_else
  277.             $_if <cmp CH, 4>, E
  278.                 mov    CL, test_data[BX]
  279.                 mov    CH, 08h
  280.             $_endif
  281.         $_endif
  282.         call test_proc
  283.     $_endfor
  284.  
  285.  $_SWITCH Multiple branches.
  286.  ===========================
  287.  SYNTAX:
  288.  -------
  289.  
  290.     $_switch [ register ] [,block ]
  291.         $_case condition_1-1
  292.         [ $_c condition_1-2 ]
  293.           :
  294.         [ $_c condition_1-n ]
  295.                 :
  296.                 :
  297.             [ $_break [ block ] ]
  298.         $_case condition_2-1
  299.         [ $_c condition_2-2 ]
  300.            :
  301.         [ $_c condition_2-n ]
  302.                 :
  303.                 :
  304.             [ $_break [ block ] ]
  305.             :
  306.          $_case condition_m-1
  307.          [ $_c condition_m-2 ]
  308.             :
  309.          [ $_c condition_m-n ]
  310.                  :
  311.                  :
  312.              [ $_break [ block ] ]
  313.          [$_default]
  314.                  :
  315.                  :
  316.        $_endswitch
  317.  
  318.  
  319.   
  320.  SUMMARY:    Evaluates <$_c condition_j-k> and executes any line(s)
  321.  -------     associated with <$_c condition_j> whose value matches
  322.              the initial expression. If there is no match with a
  323.              condition(s), the lines associated with the $_default
  324.              is executed. If the $_default is not given, control passes
  325.              to the block following the $_endswitch block. You may
  326.              execute only one of the block which fits your condition
  327.              by inserting $_break.
  328.              
  329.              Use of a register enables fast branching with the use of
  330.              address conversion table. You may specify one of these
  331.              registers:
  332.                  BX,BP,SI,DI
  333.              with conditions call by parameters like "<3,5ah,7>", without
  334.              using $_c macro. The value of the parameters must be less
  335.              than 128. You must prepare $_table, data macro, inside the
  336.              block.
  337.  
  338.  
  339.  EXAMPLE:
  340.  -------
  341.     $_switch
  342.         $_case <cmp AH, 0>, E
  343.             mov    BH, ON
  344.             $_break
  345.         $_case <cmp AH, 1>, E
  346.             mov    AX, 0200h
  347.             $_break
  348.         $_default
  349.             inc    tbl_ptr
  350.     $_endswitch
  351.  
  352.  EXAMPLE: Use of a register for multiple selection. You must use
  353.  -------  UPPER CASE for the name of the register.
  354.           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  355.  
  356.     $_switch  BX
  357.         $_case <0, 2, 4, 6>
  358.             mov    CX, 1
  359.             $_break
  360.         $_case <1, 3, 5, 7>
  361.             mov    CX, 0
  362.             $_break
  363.         $_default
  364.             mov    CX, 0ffffh
  365.     $_endswitch
  366.     :
  367.     :
  368.     $_table                 ; you must supply a table in the data area.
  369.     :
  370.  
  371.  
  372.  $_BREAK Exit from Repeating or Selection structures.
  373.  ====================================================
  374.  
  375.  SYNTAX:
  376.  -------
  377.  
  378.    $_break [ block ] [,< cmd>, operator ]
  379.  
  380.  SUMMARY:  You can exit from the control structure where your
  381.  -------   control is presently resides, with $_break, in any
  382.            type of control structure described above.
  383.            If you supply block name after $_break, control is passed to
  384.            the block. Or you may specify an operator following a command
  385.            which decides the exit.
  386.  
  387.  
  388.  
  389.  
  390.  $_C Conditional.
  391.  ===============
  392.  SYNTAX:
  393.  ------
  394.     Macro < Command >, Operator,[ Logical Operator ]
  395.  
  396.  SUMMARY: Describe conditions for branch on condition or selection
  397.  -------- by condition. You may execute a line before the evaluation
  398.           of the condition, else you will evaluate the result of
  399.           the preceding block.
  400.  EXAMPLE:
  401.  --------
  402.     :                ;this is the line preceding before evaluation
  403.     $_if <>, GE
  404.        :
  405.        :
  406.     $_endif
  407.  
  408.  NOTE:    The following operators can be used as comparison operators:
  409.  ----     A,AE,B,BE,C,E,G,GE,L,LE,NA,NAE,NB,NBE,NC,NE,NG,NGW,NL,NLE
  410.           NO,NP,NS,NZ,O,PE,PO,S,Z.
  411.           
  412.           Logical operators are to be used for the logical relations
  413.           among multiple conditions. You can use AND and OR.
  414.           Always AND is evaluated first and the OR 's are evaluated.
  415.           Associative laws of Boolean algebra can be applied with
  416.           Logical ORs and ANDs. You must use UPPER CASE for OPERATORS.
  417.                                              ^^^^^^^^^^^^^^^^^^^^^^^^
  418.  
  419.  EXAMPLE.
  420.  -------
  421.  
  422.     $_if < command line >, OPERATOR, AND --+---------------------*
  423.     $_c  < command line >, OPERATOR, OR  --*                     +
  424.     $_c  < command line >, OPERATOR, AND -------*                |
  425.     $_c  < command line >, OPERATOR, AND        +---------------=:
  426.     $_c  < command line >, OPERATOR, OR  -------*                +
  427.     $_c  < command line >, OPERATOR, ----------------------------*
  428.          :
  429.          :
  430.     $_endif
  431.  
  432.   NOTE:  Combined conditions are expressed by $_c Macros.
  433.          You may call $_c Macro after evaluating a condition with logical
  434.          operators, including $_c macro may be.
  435.          A line or lines may be executed between $_c Macros.
  436.   
  437.  
  438.     $_if <cmp AX, 1>, NE, AND
  439.     mov    BX, test_idx               ; line executed before next $_c.
  440.     $_c <cmp test_data[BX], 10h>, E
  441.         :
  442.         :
  443.     $_endif
  444.  
  445.  $_MACRO_ Offset for conditional Branch.
  446.  ======================================
  447.  SYNTAX:
  448.  -------
  449.      $_macro  -----> $_macro_ .
  450.  
  451.  SUMMARY:  Macros defined and explained above will generate labels and
  452.  --------  branch or jump on condition(s). Since branch and jump are
  453.            all relative jumps in 8086 processor, you must supply some
  454.            information for the relative jumps of offset more than 128
  455.            in size. The information is specified by adding  trailing '_'
  456.            to a macro.
  457.  
  458.  EXAMPLE:
  459.  --------
  460.  
  461.     $_if_ <cmp AX, 0>, E
  462.             :
  463.             :
  464.             :
  465.             :
  466.             :
  467.     $_else_
  468.             :
  469.             :
  470.             :
  471.             :
  472.     $_endif_
  473.  
  474.  NOTE:   If you use SLR's OPTASM, you will not need this trailing
  475.          underscore. OPTASM will take all the care of large offset
  476.          above 128.
  477.  
  478.  
  479.  RESTRICTION.
  480.  ============
  481.    The depth of nesting in AMSCLS is at most 16, where you count
  482.    each branch 1, each repeating structure 2. To the best of my
  483.    knowledge, the number of a label in a code segment has no
  484.    restriction from our macro set structure. There is definitely
  485.    an upper limit from MASM it self.
  486.  
  487.  
  488.  $_PUSH,$POP ,store and restore registers.
  489.  =========================================
  490.  
  491.  SYNTAX:
  492.  -------
  493.     $_push < registers > [, identifier ]
  494.        :
  495.        :
  496.        :
  497.     $_pop [ identifier ]
  498.  
  499.  SUMMARY: A group of parameter values on specified registers is pushed
  500.  -------- in with identifier. There is no need to use an identifier if
  501.           you are in a simple situation. If you nest PUSH and POPs in
  502.           a block, you had better assign an identifier. The parameter
  503.           values are restored by calling a $_pop macro with the same
  504.           identifier.
  505.  
  506.  EXAMPLE:
  507.  --------
  508.  
  509.     $_push    <ax, bx, cx, di, ds>, 01
  510.     xor    bx, bx
  511.     mov    ds, bx
  512.     :
  513.     :
  514.     :
  515.     $_pop 01
  516.  
  517.  
  518.  4. REMARKS.
  519.   ~~~~~~~~~
  520.     This macro set was programmed when I was just started to program
  521.   Micro-Computers. Cap!Niss, Takuya Nishimura wrote an article for this
  522.   macro set with three structures of his own contribution. Similarly,
  523.   this document itself is a revision of his original document in the
  524.   disk service version from ASCII cooperations.
  525.     I have done a similar macro-package for MACRO-80 assembler.
  526.   I can supply the MACRO-80 version, source code only upon request.
  527.  
  528.  
  529.   5. Distribution and Copyright.
  530.     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  531.  This package, amscls.doc and amscls.inc, is under the protection of
  532.  Copyright. You may use this software for the programming with any language
  533.  on the condition that you add the following copyright to your product.
  534.  
  535.  
  536.    A-MACROS / Control Logic Structure Macros. 
  537.    AMSCLS.INC (c) Hortense S. Endoh 1986, 1987
  538.  
  539.  
  540.  You may copy and redistribute this software through BBS. We would
  541.  appreciate if you would continue to upload the future revisions.
  542.  You must distribute this document with the Macro Package, too.
  543.  
  544.  
  545.  6. How to contact us :
  546.  ~~~~~~~~~~~~~~~~~~~~~~ 
  547.  Hortense S. Endoh  ASCII-NET (PCS) pcs17331
  548.                     NIFTY-SERVE GGH03436
  549.                     Nikkei-MIX  hortense
  550.  
  551.  Or E-mail K.OKUBO at 74100,2565 compuserve
  552.                       K.OKUBO Genie
  553.                       okubok@tansei.cc.u-tokyo.ac.jp
  554.  12/Feb/1991
  555.