home *** CD-ROM | disk | FTP | other *** search
/ Vectronix 2 / VECTRONIX2.iso / FILES_10 / DEVELOP.LZH / DSP / C56K / MC.DOC < prev   
Text File  |  1979-12-09  |  132KB  |  3,296 lines

  1.     
  2.     
  3.     
  4.     
  5.     
  6.     
  7.     
  8.     
  9.     
  10.     
  11.     
  12.     
  13.     
  14.     
  15.     
  16.     
  17.     
  18.     
  19.     
  20.     
  21.                                     MICRO-C
  22.     
  23.                              A compact 'C' compiler
  24.                                for small systems.
  25.     
  26.     
  27.     
  28.     
  29.     
  30.                                   Release 1.2
  31.                                Revised 28-Jul-89
  32.     
  33.     
  34.     
  35.     
  36.     
  37.     
  38.     
  39.     
  40.     
  41.     
  42.     
  43.     
  44.     
  45.     
  46.     
  47.                                        By
  48.                                  Dave Dunfield
  49.     MICRO-C                                                          Page: 1
  50.  
  51.  
  52.     1. INTRODUCTION
  53.     
  54.           MICRO-C is a compact, portable compiler for a subset  of  the  'C'
  55.        language which is suitable for implementation on small 8  or  16  bit
  56.        computer systems. It may be used as a resident or cross compiler, and
  57.        is capable of generating ROMable code. It is  distributed  in  source
  58.        form, and thus provides a learning tool for those wishing to  examine
  59.        the internals of a working compiler.
  60.     
  61.           The main goal in the development of MICRO-C, has been to provide a
  62.        reasonably powerful language  which  will  be  portable  with  little
  63.        difficulty to many target systems. The 'C' language was  designed  to
  64.        be portable, and provides  ample  programming  power,  hence  it  was
  65.        chosen. MICRO-C provides  an  alternative  to  interpreted  BASIC  or
  66.        assembly language programming which  are  often  the  only  languages
  67.        available on small 8 bit systems.
  68.     
  69.           With today's focus on larger computers and workstations,  software
  70.        support for small  systems  and  micro-controller  sized  devices  is
  71.        getting hard to find. MICRO-C helps fills that gap, because all files
  72.        necessary to port the compiler are included on the distribution disk,
  73.        allowing it to be  moved  to  ANY  system  without  dependance  on  a
  74.        software vendor.
  75.     
  76.           Also included with the compiler is the 'C' source  code  for  some
  77.        common "library" routines, as well  as  code  generators  for  a  few
  78.        popular microprocessors.
  79.     
  80.           Users writing new code  generators  and/or  library  routines  are
  81.        encouraged to send them back to  me  for  inclusion  in  the  MICRO-C
  82.        distribution disk.
  83.     
  84.           The MICRO-C "package" (software  and  documentation)  is  free  to
  85.        anyone  wishing  to  use  it,  provided  that  no  part  of   it   is
  86.        re-distributed for profit or other  commercial  purposes  without  my
  87.        written permission. Although  no  fee  is  charged  for  the  use  of
  88.        MICRO-C, I retain ownership and copyright  of  the  programs,  source
  89.        files and documents.
  90.     
  91.           Users are encouraged to copy and re-distribute MICRO-C as long  as
  92.        no fee (other than "usual" system access or disk copy service fee) is
  93.        charged. I also request that any changes to the original  package  be
  94.        clearly marked as such.
  95.     
  96.           MICRO-C is provided on an "as is" basis, with no warranty  of  any
  97.        kind. In no event shall the author be liable for any damages  arising
  98.        from its use or distribution.
  99.     
  100.                            Dave Dunfield
  101.                            56 Burnetts Grove Circle,
  102.                            Nepean, Ont.
  103.                            K2J 1N6
  104.                            (613) 825-0257
  105.     MICRO-C                                                          Page: 2
  106.  
  107.  
  108.        1.1 Code Portability
  109.     
  110.              With a few exceptions, this compiler follows the syntax of  the
  111.           "standard" UNIX compiler (within  its  subset  of  the  language).
  112.           Programs written in MICRO-C should compile with few changes  under
  113.           other "standard" compilers.
  114.     
  115.           1.1.1 Unsupported Features:
  116.     
  117.                 MICRO-C does not currently support the following features of
  118.              standard 'C':
  119.     
  120.                     Long, Double, Float and Enumerated data types, Structures,
  121.                     Unions, Typedef, Typecast and Bit fields.
  122.     
  123.           1.1.2 Additional Features
  124.     
  125.                 MICRO-C provides a few additional  features  which  are  not
  126.              always included in "standard" 'C' compilers:
  127.     
  128.                     Unsigned character variables, Nested comments, 16 bit
  129.                     character constants, Inline assembly code capability.
  130.     
  131.        1.2 Compiler Portability
  132.     
  133.              MICRO-C is written in standard 'C', and is capable of compiling
  134.           itself. This allows any system  with  a  'C'  compiler  (including
  135.           MICRO-C) to be used to port MICRO-C to another processor.
  136.     
  137.              The  parser  makes  very  few  assumptions  about  the   target
  138.           processor  or  operating  system  architecture,  allowing  a  code
  139.           generator  to  be  written  for  virtually   any   processor   and
  140.           environment.
  141.     
  142.              With the exception of required I/O routines (described  later),
  143.           the MICRO-C compiler uses no library functions, and relies  on  no
  144.           system services.
  145.     
  146.              Assuming that the code generator is fairly efficent,  and  that
  147.           the I/O routines and code generator are not unreasonably large,  a
  148.           full MICRO-C compiler may be implemented on systems with as little
  149.           as 32K of free ram and a single floppy disk.
  150.     MICRO-C                                                          Page: 3
  151.  
  152.  
  153.        1.3 The MCC command
  154.     
  155.              When  created  using  the  'io'  routines   supplied   on   the
  156.           distribution disk, the format of the MICRO-C Compiler command line
  157.           is:
  158.     
  159.                     MCC [input_file] [output_file] [options]
  160.     
  161.              [input_file] is the name of  the  source  file  containing  'C'
  162.           statements to read. If no filenames are given, MCC will read  from
  163.           standard input.
  164.     
  165.              [output_file] is the name of the file to  write  the  generated
  166.           assembly  language  code  to.  If  less  than  two  filenames  are
  167.           specified, MCC will write to standard output.
  168.     
  169.           1.3.1 Command Line Options
  170.     
  171.                 MCC accepts the following command line [options]:
  172.     
  173.                 -q      - Instructs MCC to be quiet, and not display the
  174.                           startup message when it is executed.
  175.     
  176.        1.4 Command files
  177.     
  178.              Several command (batch) files are included with MICRO-C,  which
  179.           simplify operation of the compiler:
  180.     
  181.              The 'CC' command file  compiles  and  assembles  a  single  'C'
  182.           source file, which is then linked with the librarys to produce  an
  183.           executable module. This provides a "one step"  compile  when  only
  184.           one source file is involved.
  185.     
  186.                                  eg: CC ONEPROG
  187.     
  188.              The 'CCO' command file compiles  and  assembles  a  single  'C'
  189.           source file, producting a linkable module.  This  allows  multiple
  190.           source files used in a single program to be compiled seperately.
  191.     
  192.                                 eg: CCO FIRST
  193.                                     CCO SECOND
  194.     
  195.              The 'LC' command file links one or  more  modules  produced  by
  196.           'CCO' with the libraries to produce  an  executable  module.  This
  197.           module will be given the name of the first file specified  in  the
  198.           argument list.
  199.     
  200.                               eg: LC FIRST SECOND
  201.     
  202.              If you wish to make use of the enhanced preprocessor  (MCP)  or
  203.           the optimizer (MCO), you may modify the above file  to  suit  your
  204.           needs.
  205.     MICRO-C                                                          Page: 4
  206.  
  207.  
  208.     2. THE MICRO-C PROGRAMMING LANGUAGE
  209.     
  210.           The following pages contain a brief summary of  the  features  and
  211.        constructs implemented in MICRO-C.
  212.     
  213.           This document does not  attempt  to  teach  'C'  programming,  and
  214.        assumes that the reader is familiar with the language.
  215.     
  216.        2.1 Constants
  217.     
  218.              The following forms of constants are supported by the compiler:
  219.     
  220.                 <num>       - Decimal number (num = 0-65535)
  221.                 0<num>      - Octal number (num = 0 - 177777)
  222.                 0x<num>     - Hexidecimal number (num = 0-ffff)
  223.                 '<char>'    - Character (1 or 2 characters)
  224.                 "<string>"  - Address of literal string.
  225.     
  226.              The following "special" characters may be used within character
  227.           constants or strings:
  228.     
  229.                 \n          - Newline (line-feed)   (0x0a)
  230.                 \r          - Carriage Return       (0x0d)
  231.                 \t          - Tab                   (0x09)
  232.                 \f          - Formfeed              (0x0c)
  233.                 \b          - Backspace             (0x08)
  234.                 \<num>      - Octal value <num>     (Max. three digits)
  235.                 \x<num>     - Hex value <num>       (Max. two digits)
  236.                 \<char>     - Protect character <char> from input scanner.
  237.     
  238.        2.2 Symbols
  239.     
  240.              Symbol  name  may  include  the  characters  'a'-'z',  'A'-'Z',
  241.           '0'-'9', and '_'. The characters '0'-'9' may not be  used  as  the
  242.           first character in the  symbol  name.  Symbol  names  may  be  any
  243.           length, however, only the first 15 characters are significant.
  244.     
  245.              The "char" modifier may be used to declare a symbol as an 8 bit
  246.           wide value, otherwise it is assumed to be 16 bits.
  247.     
  248.                               eg: char input_char;
  249.     
  250.              The "int" modifier may be used to declare a symbol as a 16  bit
  251.           wide value. This is assumed if neither "int" or "char" is given.
  252.     
  253.                                   eg: int abc;
  254.     
  255.              The "unsigned" modifier may be used to declare a symbol  as  an
  256.           unsigned positive only value. Note that unlike some 'C' compilers,
  257.           this modifier may be applied to a character (8 bit) variable.
  258.     
  259.                             eg: unsigned char count;
  260.     MICRO-C                                                          Page: 5
  261.  
  262.  
  263.              The "extern" modifier causes the compiler to be  aware  of  the
  264.           existance and type of a global symbol, but not generate  any  code
  265.           to define that symbol. This allows the module  being  compiled  to
  266.           reference a symbol  which  is  defined  in  another  module.  This
  267.           modifier may not be used with local symbols.
  268.     
  269.                             eg: extern char getc();
  270.     
  271.              A  symbol  declared  as  external  may  be  re-declared  as   a
  272.           non-external at a later point in the code, in which case code  for
  273.           it will be generated. This allows "extern" to be  used  to  inform
  274.           the compiler of a function or variable type  so  that  it  can  be
  275.           properly used before that symbol is actually declared.
  276.     
  277.              The "static" modifier causes global variables to  be  generated
  278.           at the point in the code where they are defined, causing  them  to
  279.           be included in the object code image when it  is  saved  to  disk.
  280.           Static variables are  automatically  initialzed  to  zero  by  the
  281.           compiler. Static variables within a function  definition  are  not
  282.           allowed.
  283.     
  284.                          eg: static int variable_name;
  285.     
  286.              The "register" modifier indicates to the  code  generator  that
  287.           this is a high priority variable, and should be kept where  it  is
  288.           easy to get at. Since  its  interpretation  depends  on  the  code
  289.           generator, it is often  ignored  in  simple  implementations.  See
  290.           "Functions" for a  special  use  of  "register"  when  defining  a
  291.           function.
  292.     
  293.                           eg: register unsigned count;
  294.     
  295.              Symbols declared with a preceeding '*' are assumed to be 16 bit
  296.           pointers to the declared type.
  297.     
  298.                              eg: int *pointer_name;
  299.     
  300.              Symbol names declared followed by square brackets  are  assumed
  301.           to be arrays with a number of dimensions equal to  the  number  of
  302.           '[]' pairs that follow. The size of each dimension  is  identified
  303.           by a constant value  contained  within  the  corresponding  square
  304.           brackets.
  305.     
  306.                           eg: char array_name[5][10];
  307.     
  308.           2.2.1 More Symbol Examples
  309.     
  310.                 char a;                 /* 8 bit signed */
  311.                 unsigned char b;        /* 8 bit unsigned */
  312.                 int c;                  /* 16 bit signed */
  313.                 unsigned int d;         /* 16 bit unsigned */
  314.                 unsigned e;             /* also 16 bit unsigned */
  315.                 extern char f();        /* external function returning char */
  316.     MICRO-C                                                          Page: 6
  317.  
  318.  
  319.           2.2.2 Global Symbols
  320.     
  321.                 Symbols  declared  outside  of  a  function  definition  are
  322.              considered to  be  global  and  will  have  memory  permanently
  323.              reserved for them. Global symbols are defined by  name  in  the
  324.              output file, allowing other modules to access them.
  325.     
  326.                 Note that the compiler IS case  sensitive,  however  if  the
  327.              assembler you are using is NOT, you  must  be  careful  not  to
  328.              declare any global symbols with names that differ only in case.
  329.     
  330.                 All non-static global variables are generated  at  the  very
  331.              end of the output file, after the literal pool is dumped. Since
  332.              non-static globals do not generate code, this allows them to be
  333.              excluded from the image file when it is saved to disk.
  334.     
  335.                 Global variables may be initialized with one or more values,
  336.              which are expressed as a single array of  integers  REGUARDLESS
  337.              of the size and shape of the variable. If more than  one  value
  338.              is expressed, '{' and '}' must be used.
  339.     
  340.                    eg: int i = 10, j[2][2] = { 1, 2, 3, 4 };
  341.     
  342.                 When arrays are declared, a null dimension may  be  used  as
  343.              the dimension size, in which case the size of  the  array  will
  344.              default to the number of initialized values.
  345.     
  346.                          eg: int array[] = { 1, 2, 3 };
  347.     
  348.                 Initialized global variables are  automatically  defined  as
  349.              STATIC, which insures that the inital values will be  saved  in
  350.              the code image. Any  non-initialized  elements  of  the  static
  351.              variable will be set to zero.
  352.     
  353.                 Non-static global variables are not initialized in any  way,
  354.              and will be undefined at the beginning of program execution.
  355.     
  356.           2.2.3 Local Symbols
  357.     
  358.                 Symbols declared within a function definition are  allocated
  359.              on the stack, and  exist  only  during  the  execution  of  the
  360.              function.
  361.     
  362.                 To simplify the allocation and de-allocation of stack space,
  363.              all local symbols must be declared  at  the  beginning  of  the
  364.              function before any code producing statements are encountered.
  365.     
  366.                 MICRO-C does not support initialization of  local  variables
  367.              in the declaration statement. Since local variables have to  be
  368.              initialized every time the function is entered, you can get the
  369.              same effect using assignment statements at the beginning of the
  370.              function.
  371.     
  372.                 No type is assumed for  arguments  to  functions.  Arguments
  373.              must be explicitly declared, otherwise they will  be  undefined
  374.              within the scope of the function definition.
  375.     MICRO-C                                                          Page: 7
  376.  
  377.  
  378.        2.3 Arrays & Pointers
  379.     
  380.              When MICRO-C passes an array to a function, it actually  passes
  381.           a POINTER to the array. References to arrays which  are  arguments
  382.           are automatically performed through the pointer.
  383.     
  384.              This allows the use of pointers and arrays to be interchangable
  385.           through the context of a function call. Ie: An array passed  to  a
  386.           function may be declared and used as  a  pointer,  and  a  pointer
  387.           passed to a function may be declared and used as an array.
  388.     
  389.        2.4 Functions
  390.     
  391.              Functions are  essentially  initialized  global  symbols  which
  392.           contain executable code. They are always "static" and  are  always
  393.           exist in the code image.
  394.     
  395.              MICRO-C accepts  any  valid  value  as  a  function  reference,
  396.           allowing  some  rather  unique  (although  non-standard)  function
  397.           calls.
  398.     
  399.           For example:
  400.     
  401.                 function();     /* call function */
  402.                 variable();     /* call contents of a variable */
  403.                 (*var)();       /* call indirect through variable */
  404.                 (*var[x])();    /* call indirect through indexed array */
  405.                 0x5000();       /* call address 0x5000 */
  406.     
  407.              Since this is a single pass compiler, operands to functions are
  408.           evaluated and pushed on the stack in the order in which  they  are
  409.           encountered, leaving the last operand closest to the  top  of  the
  410.           stack. This is the opposite order from which  many  'C'  compilers
  411.           push operands.
  412.     
  413.              For functions with a fixed number of arguments,  the  order  of
  414.           which operands  are  passed  is  of  no  importance,  because  the
  415.           compiler looks after generating  the  proper  stack  addresses  to
  416.           reference variables.  HOWEVER,  functions  which  use  a  variable
  417.           number of arguments are affected for two reasons:
  418.     
  419.           1) The location of the LAST arguments are known (as fixed  offsets
  420.              from the stack pointer) instead of the FIRST.
  421.     
  422.           2) The symbols defined as arguments  in  the  function  definition
  423.              represent the LAST arguments instead of the FIRST.
  424.     
  425.              If a function is declared as "register", it  serves  a  special
  426.           purpose and causes the accumulator to be loaded with the number of
  427.           arguments passed whenever the function is called. This allows  the
  428.           function to know how many  arguments  were  passed  and  therefore
  429.           determine the location of the first argument.
  430.     MICRO-C                                                          Page: 8
  431.  
  432.  
  433.        2.5 Control Structures
  434.     
  435.              The following control statements are implemented in MICRO-C:
  436.     
  437.                 if(expression)
  438.                     statement;
  439.     
  440.                 if(expression)
  441.                     statement;
  442.                 else
  443.                     statement;
  444.     
  445.                 while(expression)
  446.                     statement;
  447.     
  448.                 do
  449.                     statement;
  450.                 while expression;
  451.     
  452.                 for(expression; expression; expression)
  453.                     statement;
  454.     
  455.                 return;
  456.     
  457.                 return expression;
  458.     
  459.                 break;
  460.     
  461.                 continue;
  462.     
  463.                 switch(expression) {
  464.                     case constant_expression :
  465.                         statement;
  466.                         ...
  467.                         break;
  468.                     case constant_expression :
  469.                         statement;
  470.                         ...
  471.                         break;
  472.                         .
  473.                         .
  474.                         .
  475.                     default:
  476.                         statement; }
  477.     
  478.                 label: statement;
  479.     
  480.                 goto label;
  481.     MICRO-C                                                          Page: 9
  482.  
  483.  
  484.     2.5.1 Notes on Control Structures
  485.     
  486.         1)  Any "statement" may be a single statement or a compound
  487.             statement enclosed within '{' and '}'.
  488.     
  489.         2)  All three "expression"s in the "for" command are optional.
  490.     
  491.         3)  If a "case" selection does not end with "break;", it will
  492.             "fall through" and execute the following case as well.
  493.     
  494.         4)  Expressions following 'return' and 'do/while' do not have
  495.             to be contained in brackets (although this is permitted).
  496.     
  497.         5)  Label names may preceed any statement, and must be any
  498.             valid symbol name, followed IMMEDIATELY by ':' (No spaces
  499.             are allowed). Labels are considered LOCAL to a function
  500.             definition and will only be accessable within the scope
  501.             of that function.
  502.     MICRO-C                                                          Page: 10
  503.  
  504.  
  505.        2.6 Expression Operators
  506.     
  507.              The following expression operators are implemented in MICRO-C:
  508.     
  509.     2.6.1 Unary Operators
  510.     
  511.         -           - Negate
  512.         ~           - Complement
  513.         !           - Logical complement
  514.         ++          - Pre or Post increment
  515.         --          - Pre or post decrement
  516.         *           - Indirection
  517.         &           - Address of
  518.     
  519.     2.6.2 Binary Operators
  520.     
  521.         +           - Addition
  522.         -           - Subtraction
  523.         *           - Multiplication
  524.         /           - Division
  525.         %           - Modulus
  526.         &           - Bitwise AND
  527.         |           - Bitwise OR
  528.         ^           - Bitwise exclusive OR
  529.         <<          - Shift left
  530.         >>          - Shift right
  531.         ==          - Test for equality
  532.         !=          - Test for inequality
  533.         >           - Test for greater than
  534.         <           - Test for less than
  535.         >=          - Test for greater than or equal to
  536.         <=          - Test for less than or equal to
  537.         &&          - Logical AND
  538.         ||          - Logical OR
  539.         =           - Assignment
  540.         +=          - Add to self assignment
  541.         -=          - Subtract from self assignment
  542.         *=          - Multiply by self assignment
  543.         /=          - Divide by and reassign assignment
  544.         %=          - Modular self assignment
  545.         &=          - AND with self assignment
  546.         |=          - OR with self assignment
  547.         ^=          - XOR with self assignment
  548.         <<=         - Shift left self assignment
  549.         >>=         - Shift right self assignment
  550.     MICRO-C                                                          Page: 11
  551.  
  552.  
  553.     NOTES:
  554.     
  555.         1)  The expression "a && b" returns 0 if "a" is zero, otherwise the
  556.             value of "b" is returned. The "b" operand is NOT evaluated if
  557.             "a" is zero.
  558.     
  559.         2)  The expression "a || b" returns the value of "a" if it is not 0,
  560.             otherwise the value of "b" is returned. The "b" operand is NOT
  561.             evaluated if "a" is non-zero.
  562.     
  563.     2.6.3 Other Operators
  564.     
  565.         ;           - Ends a statement.
  566.         ,           - Allows several expressions in one statement.
  567.                     - Separates symbol names in multiple declarations.
  568.                     - Separates constants in multi-value initialization.
  569.                     - Separates operands in function calls.
  570.         ?           - Conditional expression.
  571.         :           - Delimits labels, ends CASE and separates conditionals.
  572.         { }         - Defines a block of statements.
  573.         ( )         - Forces priority in expression, indicates function calls.
  574.         [ ]         - Indexes arrays. If fewer index values are given than the
  575.                       number of dimensions which are defined for the array, the
  576.                       the value returned will be a pointer to the appropriate
  577.                       address.
  578.     
  579.                     Eg:
  580.                         char a[5][2];
  581.     
  582.                         a[3] returns address of forth row of two elements.
  583.                         (remember index's start from zero)
  584.     
  585.                         a[3][0] returns the character at index [3][0];
  586.     MICRO-C                                                          Page: 12
  587.  
  588.  
  589.        2.7 Preprocessor Commands
  590.     
  591.              The  MICRO-C  compiler  supports  the  following  pre-processor
  592.           commands. These commands are recognized only if they occur at  the
  593.           beginning of the input line.
  594.     
  595.           2.7.1 #asm
  596.     
  597.                 Causes the compiler to copy all subsequent lines directly to
  598.              the output  file  without  translation.  This  allows  assembly
  599.              language code to be included in the 'C' program.
  600.     
  601.           2.7.2 #endasm
  602.     
  603.                 Terminates a "#asm",  and  causes  the  compiler  to  resume
  604.              compiling from the input file.
  605.     
  606.           2.7.3 #define <name> <replacement_text>
  607.     
  608.                 The "#define" command allows a global name  to  be  defined,
  609.              which will be replaced with the inicated text  whenever  it  is
  610.              encountered in the input file. This occurs prior to  processing
  611.              by the compiler.
  612.     
  613.           2.7.4 #include <filename>
  614.     
  615.                 This command causes the indicated file to be opened and read
  616.              in as the source  text.  When  the  end  of  the  new  file  is
  617.              encountered, processing will continue with the  line  following
  618.              "#include" in the original file.
  619.     
  620.           2.7.5 #ifdef <name>
  621.     
  622.                 Processes the following lines (up to #else of  #endif)  only
  623.              if the given name is defined.
  624.     
  625.           2.7.6 #ifndef <name>
  626.     
  627.                 Processes the following lines (up to #else of  #endif)  only
  628.              if the given name is NOT defined.
  629.     
  630.           2.7.7 #else
  631.     
  632.                 Processes the following lines (up to  #endif)  only  if  the
  633.              preceeding #ifdef or #ifndef was false.
  634.     
  635.           2.7.8 #endif
  636.     
  637.                 Terminates #ifdef and #ifndef
  638.     
  639.                 NOTE: The #ifdef and #ifndef contructs may not be nested  in
  640.              MICRO-C.
  641.     MICRO-C                                                          Page: 13
  642.  
  643.  
  644.        2.8 Error Messages
  645.     
  646.              When MICRO-C detects an  error,  it  outputs  an  informational
  647.           message indicating the type of problem encountered.
  648.     
  649.              The error message is preceeded by the line numbers of the  line
  650.           containing the error in all files being processed.
  651.     
  652.                              eg: 5:3: Syntax error
  653.     
  654.              In the above example, the main input file "#included" a file at
  655.           line 5, and a syntax error was discovered in that file at line 3.
  656.     
  657.              The following error messages are produced by the compiler:
  658.     
  659.           2.8.1 Compilation aborted
  660.     
  661.                 The preceeding error was so severe than the compiler  cannot
  662.              proceed.
  663.     
  664.           2.8.2 Constant expression required
  665.     
  666.                 The compiler requires a constant  expression  which  can  be
  667.              evaluated at compile time (ie: no variables).
  668.     
  669.           2.8.3 Declarations must preceed code.
  670.     
  671.                 All local variables must be defined at the beginning of  the
  672.              function, before any code producing statements are processed.
  673.     
  674.           2.8.4 Dimension table exhausted
  675.     
  676.                 The compiler has encountered more  active  array  dimensions
  677.              than it can handle.
  678.     
  679.           2.8.5 Duplicate local: 'name'
  680.     
  681.                 You have declared the named  local  symbol  more  than  once
  682.              within the same function definition.
  683.     
  684.           2.8.6 Duplicate global: 'name'
  685.     
  686.                 You have declared the named global symbol more than once.
  687.     
  688.           2.8.7 Expected '<token>'
  689.     
  690.                 The compiler  was  expecting  the  given  token,  but  found
  691.              something else.
  692.     
  693.           2.8.8 Expression stack overflow
  694.     
  695.                 The compiler has found a more complicated expression than it
  696.              can handle. Check that it is of  correct  syntax,  and  if  so,
  697.              break it up into two simpler expressions.
  698.     MICRO-C                                                          Page: 14
  699.  
  700.  
  701.           2.8.9 Expression stack underflow
  702.     
  703.                 The compiler has made an error in  parsing  the  expression.
  704.              Check that it is of correct syntax.
  705.     
  706.           2.8.10 Illegal global statement
  707.     
  708.                 You have used a statement outside of a  function  definition
  709.              which may only be used within a function definition.
  710.     
  711.           2.8.11 Illegal indirection
  712.     
  713.                 You have attempted to perform an indirect operation ('*'  or
  714.              '[]') on an entity which is not a pointer or array. This  error
  715.              will also result if you atempt to  index  an  array  with  more
  716.              indices than it has dimensions.
  717.     
  718.           2.8.12 Illegal nested function
  719.     
  720.                 You may not declare a  function  within  the  definition  of
  721.              another function.
  722.     
  723.           2.8.13 Illegal static local
  724.     
  725.                 Local variables may not be static. This error  also  results
  726.              if  you  attempt  to  initialize  a  local  variable   in   the
  727.              declaration statement.
  728.     
  729.           2.8.14 Improper #else/#endif
  730.     
  731.                 A #else or #endif statement is out of place.
  732.     
  733.           2.8.15 Inconsistant re-declaration: 'name'
  734.     
  735.                 You have attempted to redefine  the  named  external  symbol
  736.              with a type which does not match its previously declared type.
  737.     
  738.           2.8.16 Invalid '&' operation
  739.     
  740.                 You have attempted to reference  the  address  of  something
  741.              that has no address. This error also occurs when you attempt to
  742.              take the address of an array without giving it a  full  set  of
  743.              indicies. Since the address is already returned in  this  case,
  744.              simply drop the '&'. (The error occurs because you  are  trying
  745.              to take the address of an address).
  746.     
  747.           2.8.17 Macro expansion too deep
  748.     
  749.                 The compiler has encountered a nested macro reference  which
  750.              is too deep to be resolved.
  751.     
  752.           2.8.18 Macro space exhausted
  753.     
  754.                 The compiler has encountered  more  macro  ("#define")  text
  755.              than it has room to store.
  756.     MICRO-C                                                          Page: 15
  757.  
  758.  
  759.           2.8.19 Missing #endif
  760.     
  761.                 The end of the  file  was  encountered  when  an  #ifdef  or
  762.              #ifndef was in effect.
  763.     
  764.           2.8.20 No active loop
  765.     
  766.                 A "continue" or "break" statement was  encountered  when  no
  767.              loop is active.
  768.     
  769.           2.8.21 No active switch
  770.     
  771.                 A "case" or "default"  statement  was  encountered  when  no
  772.              "switch" statement is active.
  773.     
  774.           2.8.22 Not an argument: 'name'
  775.     
  776.                 You have declared the named variable as an argument, but  it
  777.              does not appear appear in the argument list.
  778.     
  779.           2.8.23 Non-assignable
  780.     
  781.                 You have attempted an operation which results in  assignment
  782.              of a value to an entity which cannot be assigned. (eg: 1 = 2);
  783.     
  784.           2.8.24 Numeric constant required
  785.     
  786.                 The compiler requires a constant expression which returns  a
  787.              simple numeric value.
  788.     
  789.           2.8.25 String space exhausted
  790.     
  791.                 The compiler has encountered more literal  strings  than  it
  792.              can handle.
  793.     
  794.           2.8.26 Symbol table full
  795.     
  796.                 The compiler has encountered more symbol definitions than it
  797.              can handle.
  798.     
  799.           2.8.27 Syntax error
  800.     
  801.                 The statement shown does not follow syntax rules and  cannot
  802.              be parsed.
  803.     
  804.           2.8.28 Too many active cases
  805.     
  806.                 The compiler has run out of space  for  storing  switch/case
  807.              tables. Reduce the number of active "cases".
  808.     
  809.           2.8.29 Too many #defines
  810.     
  811.                 The compiler has encountered more '#define' statements  than
  812.              it can handle. Reduce the number of #defines.
  813.     MICRO-C                                                          Page: 16
  814.  
  815.  
  816.           2.8.30 Too many errors
  817.     
  818.                 The compiler is aborting because of excessive errors.
  819.     
  820.           2.8.31 Too many includes
  821.     
  822.                 The compiler has encountered more  nested  "#include"  files
  823.              than it can handle.
  824.     
  825.           2.8.32 Too many initial elements
  826.     
  827.                 You have specified more initialization values than there are
  828.              locations in the global variable.
  829.     
  830.           2.8.33 Type clash
  831.     
  832.                 You  have  attempted  to  combine  values   which   are   of
  833.              incompatable types.
  834.     
  835.           2.8.34 Unable to open: 'name'
  836.     
  837.                 A "#include" command specified the named file,  which  could
  838.              not be opened.
  839.     
  840.           2.8.35 Undefined symbol: 'name'
  841.     
  842.                 You have referenced a name which is not defined as  a  local
  843.              or global symbol.
  844.     
  845.           2.8.36 Unresolved reference: 'name'
  846.     
  847.                 The named symbol was forward  referenced  (Such  as  a  GOTO
  848.              label), and was never defined. This error will occur at the end
  849.              of the function definition containing the reference.
  850.     
  851.           2.8.37 Unterminated function
  852.     
  853.                 The  end  of  the  file  was  encountered  when  a  function
  854.              definition was still open.
  855.     
  856.           2.8.38 Unterminated #if
  857.     
  858.                 The end of file was encountered  when  a  "#if"  or  "#else"
  859.              conditional block was being processed.
  860.     MICRO-C                                                          Page: 17
  861.  
  862.  
  863.        2.9 Quirks
  864.     
  865.              In its effort to provide the maximum  amount  of  functionality
  866.           with the minimum amount of code, MICRO-C  deviates  from  standard
  867.           'C' in some areas. The following is a short summary of  the  major
  868.           infractions and quirks:
  869.     
  870.              The operands to '#' commands are  parsed  based  on  separating
  871.           spaces, and any portion of the line not required  is  ignored.  In
  872.           particular, the '#define' command only accepts a definition up  to
  873.           the next space or tab character.
  874.     
  875.             eg: #define APLUSONE A+1        <-- uses "A+1"
  876.                 #define APLUSONE A +1       <-- uses "A"
  877.     
  878.              Comments are stripped by the token scanner, which occurs  AFTER
  879.           the '#' commands are processed.
  880.     
  881.             eg: #define NULL    /* comment */   <-- uses "/*"
  882.     
  883.              Include filenames are not delimited by '""'  or  '<>'  and  are
  884.           passed to the operating system exactly as entered.
  885.     
  886.             eg: #include /mclib/stdio.h
  887.     
  888.              The '\0' constant occuring in a string or constant will confuse
  889.           the parser into thinking that the string has terminated. (This  is
  890.           a common "BUG" in many compilers, so it is a good idea to avoid it
  891.           anyways)
  892.     
  893.             Instead of: chr = '\0';
  894.                    use: chr = 0;
  895.     
  896.              Whenever MICRO-C encounters a quoted string (double quotes), it
  897.           places it in the literal pool, and generates the  ADDRESS  of  the
  898.           string as a value. There is no special  handling  of  strings  for
  899.           array  initialization  as  in  standard  'C',  for  example,   the
  900.           declaration:
  901.     
  902.                             char array[] = "string";
  903.     
  904.           Will compile the  string  "string"  into  the  literal  pool,  and
  905.           initialize a one element array with the low byte of  its  address.
  906.           In MICRO-C, to initialize an array with the CONTENTS of a  string,
  907.           you must use a statement such as:
  908.     
  909.                   char array[] = { 's','t','r','i','n','g' };
  910.     
  911.           Note that the following declaration is perfectly valid in MICRO-C,
  912.           because it is defining a pointer which will contain the address of
  913.           the string (in the literal pool):
  914.     
  915.                              char *ptr = "string";
  916.     MICRO-C                                                          Page: 18
  917.  
  918.  
  919.              The appearence of a variable name in the argument  list  for  a
  920.           function  declaration  serves  only  to  identify  that  variables
  921.           location on the stack. MICRO-C will not define the variable unless
  922.           it is explicitly declared (between the argument list and the  main
  923.           function body). In other words, all arguments to a  function  must
  924.           be explicitly declared.
  925.     
  926.              MICRO-C is more  strict  about  its  handling  of  the  ADDRESS
  927.           operator ('&') than most other compilers. It will produce an error
  928.           message if you attempt to take the address of  a  value  which  is
  929.           already a fixed address (such as an array name without a full  set
  930.           of indicies). Since an address is already returned in such  cases,
  931.           simply drop the '&'.
  932.     
  933.              The 'x' in '0x' and '\x' is accepted in lower case only.
  934.     
  935.              When using MICRO-C to create  a  function  will  which  contain
  936.           assembly language code, remember that MICRO-C allocates all  local
  937.           variables at the beginning of a function definition, and will  not
  938.           generate the function entry code until a non-declarative statement
  939.           is encountered. In particular, since  "#asm"  is  handled  by  the
  940.           pre-processor and not seen as  a  statement  by  the  parser,  you
  941.           should use a "null" statement (';') to ensure that the entry  code
  942.           is generated prior to using "#asm" at the beginning of a function.
  943.     
  944.             eg: func()
  945.                 { ;     /* ensures "entry" code is generated */
  946.                 #asm
  947.                     assembly statements
  948.                 #endasm
  949.                 }
  950.     MICRO-C                                                          Page: 19
  951.  
  952.  
  953.     3. ADVANCED TOPICS
  954.     
  955.           This section provides information on the more advanced aspects  of
  956.        MICRO-C, which  is  generally  not  needed  for  casual  use  of  the
  957.        language.
  958.     
  959.        3.1 Conversion Rules
  960.     
  961.              MICRO-C keep track of the "type" of  each  value  used  in  all
  962.           expressions. This type identifies certin  characteristics  of  the
  963.           value,  such  as   size   range   (8/16   bits),   numeric   scope
  964.           (signed/unsigned), reference (value/pointer) etc.
  965.     
  966.              When an  operation  is  performed  on  two  values  which  have
  967.           identical "types", MICRO-C assigns that same "type" to the result.
  968.     
  969.              When the  two  value  "types"  involved  in  an  operation  are
  970.           different, MICRO-C calculates the "type" of the result  using  the
  971.           following rules:
  972.     
  973.              Note that this "calculated" result type  is  used  for  partial
  974.           results within an expression. Whenever a symbol such as a variable
  975.           or function is referenced, the type of that symbol is  taken  from
  976.           its declaration, no matter what "type" of value  was  last  stored
  977.           (variable) or returned (function).
  978.     
  979.           3.1.1 Size range
  980.     
  981.                 If both values are  direct  (not  pointer)  references,  the
  982.              result will be 8 bits only if  both  values  were  8  bits.  If
  983.              either value was 16 bits, the result will be 16 bits.
  984.     
  985.                 If one value is a pointer, and  the  other  is  direct,  the
  986.              result will be a pointer to the same size value as the original
  987.              pointer.
  988.     
  989.                 If both values were pointers, the result will be  a  pointer
  990.              to 16 bits only if both original  pointers  referenced  16  bit
  991.              values. If either pointer referenced an 8 bit value, the result
  992.              will reference an 8 bit value.
  993.     
  994.           3.1.2 Numeric Scope
  995.     
  996.                 The result of an expression is considered to be signed  only
  997.              if both original values were signed. If  either  value  was  an
  998.              unsigned value, the result is unsigned.
  999.     
  1000.           3.1.3 Reference
  1001.     
  1002.                 If either of the original values was a pointer,  the  result
  1003.              will be a pointer.
  1004.     MICRO-C                                                          Page: 20
  1005.  
  1006.  
  1007.        3.2 Assembly Language Interface
  1008.     
  1009.              Assembly language programs may be called from 'C' functions and
  1010.           vice versa. These programs may be in the form of "#asm" statements
  1011.           in the 'C' source code, or separately linked modules.
  1012.     
  1013.              When MICRO-C calls any routine ('C'  or  assembler),  it  first
  1014.           pushes all arguments to the routine onto the processor  stack,  in
  1015.           the order in  which  they  occur  in  the  argument  list  to  the
  1016.           function. This means that the LAST argument  to  the  function  is
  1017.           LOWEST on the processor stack.
  1018.     
  1019.              Arguments are always pushed as 16 bit values. Character  values
  1020.           are extended to 16 bits, and arrays are passed as 16 bit  pointers
  1021.           to the array. (MICRO-C knows that arrays which are  arguments  are
  1022.           actually  pointers,  and  automatically  references  through   the
  1023.           pointer).
  1024.     
  1025.              After pushing the arguments, MICRO-C then generates  a  machine
  1026.           language subroutine  call,  thereby  executing  the  code  of  the
  1027.           routine.
  1028.     
  1029.              Since the compiler uses the ACCUMULATOR and INDEX REGISTER,  it
  1030.           will automatically save them (if necessary) during  processing  of
  1031.           the arguments to the function (even if no arguments are  present),
  1032.           and therefore these registers do not have to be preserved  by  the
  1033.           called routine.
  1034.     
  1035.              NOTE that any other  registers  used  by  the  code  generation
  1036.           routines (register variables etc) will not be  saved  by  MICRO-C,
  1037.           and should be preserved by called functions if their content is to
  1038.           be relied on between function calls.
  1039.     
  1040.              Once the called routine returns, the arguments are removed from
  1041.           the stack by the calling program. This usually consists of  simply
  1042.           adding the number of  bytes  pushed  as  arguments  to  the  stack
  1043.           pointer.
  1044.     
  1045.              When the called function executes, the first thing usually done
  1046.           is to push any registers which must be preserved, and  to  reserve
  1047.           space on the stack for any local variables which are required.  In
  1048.           some implementations, a "base" register may also be established to
  1049.           provide a stable reference to the local variables and arguments.
  1050.     
  1051.              It is the responsibility of the called function to  remove  any
  1052.           saved registers and local variable space from the stack before  it
  1053.           returns.
  1054.     MICRO-C                                                          Page: 21
  1055.  
  1056.  
  1057.              Local variables in a  function  may  be  referenced  as  direct
  1058.           offsets from the "base" register or stack pointer.  Note  that  if
  1059.           the stack pointer is used, offsets must be adjusted for the number
  1060.           of bytes which are pushed and  popped  on  the  stack  during  the
  1061.           execution of the function.
  1062.     
  1063.              The address of a particular local variable is calculated as:
  1064.     
  1065.                                 "base register"
  1066.                                        -
  1067.                      (Size of all local variables in bytes)
  1068.                                        + 
  1069.                (size of all preceeding local variables in bytes)
  1070.     
  1071.                                     -- OR --
  1072.     
  1073.                                 "stack pointer"
  1074.                                        +
  1075.                    (# bytes pushed during function execution)
  1076.                                        +
  1077.                (size of all preceeding local variables in bytes)
  1078.     
  1079.              Arguments to a  function  may  also  be  referenced  as  direct
  1080.           offsets from the "base" register or stack  pointer,  in  much  the
  1081.           same way as local variables are.
  1082.     
  1083.              The address of a particular argument is calculated as:
  1084.     
  1085.                                 "base register"
  1086.                                        +
  1087.         (# bytes pushed at entry of function to preserve registers etc.)
  1088.                                        +
  1089.                  (Size of return address on stack (usually 2))
  1090.                                        +
  1091.                       (# arguments from LAST argument) * 2
  1092.     
  1093.                                     -- OR --
  1094.     
  1095.                                 "stack pointer"
  1096.                                        +
  1097.                    (# bytes pushed during function execution)
  1098.                                        +
  1099.                      (size of all local variables in bytes)
  1100.                                        +
  1101.         (# bytes pushed at entry of function to preserve registers etc.)
  1102.                                        +
  1103.                  (Size of return address on stack (usually 2))
  1104.                                        +
  1105.                       (# arguments from LAST argument) * 2
  1106.     
  1107.              NOTE: The (number of bytes pushed at entry of  function)  is  a
  1108.           function of the code generator,  and  depends  on  the  particular
  1109.           MICRO-C implementation. Examine  some  assembly  output  from  the
  1110.           compiler to determine the actual number on your system.
  1111.     MICRO-C                                                          Page: 22
  1112.  
  1113.  
  1114.              If a function has been declared  as  "register",  MICRO-C  will
  1115.           load the accumulator with  the  number  of  arguments  which  were
  1116.           passed, each time the function is called. This allows the function
  1117.           to determine the location of the first argument.
  1118.     
  1119.              The address of  the  first  argument  passed  to  a  "register"
  1120.           function may be calculated as:
  1121.     
  1122.                            (accumulator contents) * 2
  1123.                                        + 
  1124.                                 "base register"
  1125.                                        +
  1126.         (# bytes pushed at entry of function to preserve registers etc.)
  1127.                                        +
  1128.                  (Size of return address on stack (usually 2))
  1129.     
  1130.                                     -- OR --
  1131.     
  1132.                            (accumulator contents) * 2
  1133.                                        +
  1134.                                 "stack pointer"
  1135.                                        +
  1136.                    (# bytes pushed during function execution)
  1137.                                        +
  1138.                      (size of all local variables in bytes)
  1139.                                        +
  1140.         (# bytes pushed at entry of function to preserve registers etc.)
  1141.                                        +
  1142.                  (Size of return address on stack (usually 2))
  1143.     
  1144.              Global  variables  exist  at  absolute  addresses  and  may  be
  1145.           referenced directly by name from within assembler  programs.  Keep
  1146.           in mind however, that MICRO-C uses only the first 15 characters of
  1147.           a symbol's name. Also, many code generators will reduce  the  size
  1148.           of names even further, often using an algorithm  to  compress  the
  1149.           name rather than simply truncating it. For this reason,  it  is  a
  1150.           good idea to avoid using global symbol names which are longer than
  1151.           6 or 8 characters  if  they  are  to  be  referenced  from  within
  1152.           assembly language programs.
  1153.     MICRO-C                                                          Page: 23
  1154.  
  1155.  
  1156.        3.3 Compiling for ROM
  1157.     
  1158.              Assuming the code generator does not use such "nasty" things as
  1159.           self modifying code, the output  from  the  compiler  is  entirely
  1160.           "clean", and may be placed in Read Only Memory (ROM).
  1161.     
  1162.              The compiler places all "static" variables in the  output  file
  1163.           as part of the code image. When the  program  is  stored  in  ROM,
  1164.           those  variables  are  also  stored  in  ROM,  and  will  not   be
  1165.           modifiable. Note that any global variables which  are  initialized
  1166.           in their declaration are considered "static".
  1167.     
  1168.              When the program is to be placed in ROM, you may not initialize
  1169.           any variables which you intend to modify  later.  Those  variables
  1170.           must be explicitly initialized by code executed at  the  beginning
  1171.           of the program.
  1172.     
  1173.              Initialized variables which you do not intend to  modify  (such
  1174.           as tables etc.) may be initialized in the declaration, and will be
  1175.           permanently saved in the ROM as part of the "static" code image.
  1176.     
  1177.              The  processor  stack  pointer  must  be  set  up  before   any
  1178.           expressions are evaluated, or any function  calls  are  performed.
  1179.           This may be performed via '#asm' statements.
  1180.     
  1181.              All non-initialized global variables must be  located  in  RAM.
  1182.           The compiler usually outputs all such variables at the very end of
  1183.           the compilation, just after dumping the literal pool.  The  global
  1184.           variables may be moved to RAM by  editing  the  output  file,  and
  1185.           placing an appropriate "ORG" statement at  the  beginning  of  the
  1186.           globals.
  1187.     
  1188.              If extensive compilation for ROM is being  performed,  you  may
  1189.           want to use a version of the compiler which uses  an  intermediate
  1190.           output file (see "PORTING THE COMPILER"). This allows  a  separate
  1191.           code generator to be customized for ROM applications,  which  will
  1192.           output the appropriate stack setup instructions (this can be  done
  1193.           in "def_module()"), and locate the global variables in  RAM  (this
  1194.           can be done at the end of "def_literal()").
  1195.     MICRO-C                                                          Page: 24
  1196.  
  1197.  
  1198.     4. PORTING THE COMPILER
  1199.     
  1200.           There are two major goals to accomplish when porting  the  MICRO-C
  1201.        compiler to a new machine. The first is to make the compiler  run  in
  1202.        the new environment, and the second is to make it  produce  code  for
  1203.        that environment.
  1204.     
  1205.           These two goals do not always go hand in hand. For example, it may
  1206.        be desirable to implement a CROSS COMPILER which generates code for a
  1207.        different system from that on which it runs.
  1208.     
  1209.           The usual method of porting a compiler to system A when a  version
  1210.        of the compiler is already running on system B, is to first create  a
  1211.        compiler which runs on system B, producing code for  system  A.  This
  1212.        "new" compiler may then be used to create a compiler  which  runs  on
  1213.        system A.
  1214.     
  1215.           The compiler consists of a module "compile"  which  contains,  the
  1216.        main compiler, input scanner, regular expression parser,  and  symbol
  1217.        table management routines.  This  is  the  "static"  portion  of  the
  1218.        compiler which does not change in different implementations.
  1219.     
  1220.           To create a working compiler, the above module  must  be  compiled
  1221.        and linked with an "io" module and "code"  module.  The  "io"  module
  1222.        performs the necessary initialization and I/O to allow  the  compiler
  1223.        to run in a particular  environment  (goal  #1).  The  "code"  module
  1224.        generates  the  assembly  language  output  code  for  a   particular
  1225.        environment (goal #2).
  1226.     
  1227.           The compiler uses NO system library functions, and  relies  on  NO
  1228.        system services (other  than  those  used  by  the  "io"  and  "code"
  1229.        modules). This allows the compiler to  be  ported  to  virtually  any
  1230.        system.
  1231.     
  1232.           All fixed compiler  parameters  (such  as  table  sizes  etc)  are
  1233.        contained in the header file "compile.h".
  1234.     
  1235.           Two additional modules are provided with the  compiler.  The  file
  1236.        "intercg.c", may be linked into the compiler in  place  of  the  code
  1237.        generator, and writes a "generic" intermediate  file  which  contains
  1238.        the pseudo operation and type tokens (See Code Generator).  The  file
  1239.        "genasm.c", may be linked with the regular "io" and  "code"  routines
  1240.        to produce a utility program which reads the  intermediate  file  and
  1241.        produces the assembly language code for a specific processor.
  1242.     MICRO-C                                                          Page: 25
  1243.  
  1244.  
  1245.           Although this "split" compiling approach is slower than the  usual
  1246.        mode of direct assembly  language  production,  it  provides  several
  1247.        useful capabilities:
  1248.     
  1249.        1) The amount of ram required to  run  the  "separate"  compiler  and
  1250.           genasm programs is considerably less  than  required  to  run  the
  1251.           "stand alone" compiler.
  1252.     
  1253.        2) A single parser may be used to generate code  for  several  target
  1254.           systems, by simply running a different  version  of  the  "genasm"
  1255.           utility, which is customized for each target.
  1256.     
  1257.        3) Use of the intermediate file  allows  distribution  of  "portable"
  1258.           programs which may be processed by "genasm" for different  targets
  1259.           WITHOUT distribution of the source code.
  1260.     
  1261.        4) A program may be written which processes this  intermediate  file,
  1262.           and "optimizes" the code. Additional "pseudo operation" codes  may
  1263.           be added to the output file if the target processor is capable  of
  1264.           operations which  the  more  "generic"  MICRO-C  output  does  not
  1265.           utilize.
  1266.     
  1267.        4.1 The "io" module
  1268.     
  1269.              The "io" module required  by  the  compiler  must  contain  the
  1270.           following function definitions:
  1271.     
  1272.              The function "main()" is called by the  operating  system  when
  1273.           the MICRO-C compiler is executed. It is  responsable  for  parsing
  1274.           any parmeters and command qualifiers, opening the input and output
  1275.           files,  performing  any  other  initializations  that   might   be
  1276.           required, and then  invoking  the  function  "compile()"  with  no
  1277.           arguments. The "compile" function is internal to  the  "compile.c"
  1278.           module, and will never return. For UNIX and  other  systems  which
  1279.           support I/O redirection, "stdin" and "stdout" are often  used  for
  1280.           the input and output files.
  1281.     
  1282.              The  function  "exit(rc)"  is  called  when  the  compiler  has
  1283.           finished all processing and wishes to terminate. The value "rc" is
  1284.           a return code: 0 = Success, program compiled without error,  -1  =
  1285.           Compile was aborted due to severe errors, n  =  Compile  finished,
  1286.           but had 'n' errors.
  1287.     
  1288.              The function "put_chr(chr, flag)"  is  passed  a  character  to
  1289.           output, as well as a flag. The flag will always be zero  when  the
  1290.           character is being sent to the console terminal, or non-zero  when
  1291.           the character is to be written to the output file.
  1292.     
  1293.              The function "put_str(*ptr, flag)" is passed  a  pointer  to  a
  1294.           zero terminated string, which is to be written to the  console  or
  1295.           output file as determined by "flag".
  1296.     
  1297.              The function "put_num(number, flag)" is passed a 16 bit number,
  1298.           which is to be written in printable form to the console or  output
  1299.           file as determined by "flag".
  1300.     MICRO-C                                                          Page: 26
  1301.  
  1302.  
  1303.           4.1.1 Compiler only routines
  1304.     
  1305.                 The following I/O routines are required by the compiler, but
  1306.              not by the "genasm" program.
  1307.     
  1308.                 The function  "get_lin(*ptr)"  is  passed  a  pointer  to  a
  1309.              character array,  and  should  read  a  single  line  from  the
  1310.              currently  open  input  file  into  that  array.  The  manifest
  1311.              definition "LINE_SIZE", found in "compile.h"  may  be  used  to
  1312.              determine the maximum line length acceptable to  the  compiler.
  1313.              Return of a non-zero value indicates the end of file condition.
  1314.     
  1315.                 The  function  "f_open(*ptr)"  is  passed  a  pointer  to  a
  1316.              filename. The new file should be opened, and if successful, the
  1317.              old input file should remain open and be "stacked", so that  it
  1318.              can be later returned to. If the file was opened  successfully,
  1319.              a non-zero value should be returned. A zero value indicates  to
  1320.              the compiler that the file could not be opened.
  1321.     
  1322.                 The function "f_close()"  is  responsible  for  closing  the
  1323.              currently open input  file,  and  returning  to  the  "stacked"
  1324.              previously open one. It receives no parameters. Note:  multiple
  1325.              "opens" may  be  stacked  -  see  the  manifest  definition  of
  1326.              "INCL_DEPTH" in the "compile.h" file.
  1327.     
  1328.           4.1.2 Genasm only routines
  1329.     
  1330.                 The following  I/O  routine  is  required  by  the  "genasm"
  1331.              program, but not by the compiler.
  1332.     
  1333.                 The function "get_char()" must  return  a  single  character
  1334.              from the input file as a 16 bit number with  a  positive  value
  1335.              between 0 and 255. A '-1' is  returned  for  the  end  of  file
  1336.              condition.
  1337.     
  1338.           4.1.3 Notes on I/O module
  1339.     
  1340.              1) It is the responsibility of the "put" routines to  translate
  1341.                 the  NEWLINE  '\n'  (0x0a)  character  into  whatever   line
  1342.                 termination  character(s)  are  required   by   the   target
  1343.                 operating system.
  1344.     
  1345.              2) If unix "stdin"  and  "stdout"  are  not  used,  it  is  the
  1346.                 responsibility  of  "main"  to  display  appropriate   error
  1347.                 messages if the input or output file could not be opened.
  1348.     
  1349.                 Refer to  the  sample  "io"  modules  distributed  with  the
  1350.              compiler.
  1351.     MICRO-C                                                          Page: 27
  1352.  
  1353.  
  1354.        4.2 The "code" module
  1355.     
  1356.              In order to insure that MICRO-C is portable  to  virtually  any
  1357.           environment,  the  compiler  makes  few  assumptions   about   the
  1358.           processor or system software of  the  target  system.  The  "code"
  1359.           module is  relied  on  to  produce  all  machine  instruction  and
  1360.           assembler directives written to the output file.
  1361.     
  1362.              The only two real "assumptions" made about the target processor
  1363.           are:
  1364.     
  1365.           1) It is assumed that the target processor  has  an  "accumulator"
  1366.              register in which all math operations are performed,  and  that
  1367.              the  lower  8  bits  of   this   register   may   be   accessed
  1368.              independantly.
  1369.     
  1370.           2) It is  assumed  that  the  target  processor  has  one  "index"
  1371.              register which may be loaded with a  16  bit  value,  and  that
  1372.              memory references may be made indirectly through this register.
  1373.     
  1374.              If the target processor does not support the above features, it
  1375.           may be possible to write a code generator for it using some  other
  1376.           features of the processor.
  1377.     
  1378.              For example, if an "index" register  does  not  exist,  it  may
  1379.           often be implemented using two bytes of reserved memory.
  1380.     
  1381.              The code  generation  module  required  by  the  compiler  must
  1382.           contain the following function definitions:
  1383.     
  1384.              The function "do_asm(*ptr)" is passed a pointer to a  character
  1385.           string, which it should  write  to  the  output  file  EXACTLY  as
  1386.           passed, followed by a '\n' NEWLINE  character.  This  function  is
  1387.           used by the "#asm" directive to write directly to the output file.
  1388.     
  1389.              The function "def_module()"  is  called  at  the  beginning  of
  1390.           compilation, before any other code generator functions are called.
  1391.           It is used to output any pre-amble needed by the assembler.
  1392.     
  1393.              The function "end_module()"  is  called  at  the  very  end  of
  1394.           compilation, and is the last code generator function called. It is
  1395.           used to output any post-amble needed by the assembler.
  1396.     
  1397.              The function  "def_static(symbol)"  is  passed  am  index  into
  1398.           compiler symbol tables for a  global  static  variable,  which  is
  1399.           about to be defined. The call to this function will be immediately
  1400.           followed by a call to "init_static" or "end_static".
  1401.     
  1402.              The "init_static(token, value,  word)"  function  is  passed  a
  1403.           token and value, with which it should initialize a single  element
  1404.           of static storage. The "word" flag will be non-zero if  the  value
  1405.           is a 16 bit element. Only the "constant" tokens  (NUMBER,  STRING,
  1406.           LABEL) need be handled by this routine.
  1407.     MICRO-C                                                          Page: 28
  1408.  
  1409.  
  1410.              The  "end_static()"  function  is  called  to   terminate   the
  1411.           definition of static storage.
  1412.     
  1413.              NOTE: "init_static"  should  not  rely  on  "def_static"  being
  1414.           called first,  since  it  is  also  called  immediately  following
  1415.           "def_label" to define "switch" tables (See "do_switch"). After the
  1416.           table  is  defined,  the  compiler  will  call  "end_static()"  to
  1417.           terminate the initialization and set up for the next.
  1418.     
  1419.              The function "def_global(symbol, size)" is called at the end of
  1420.           the compile, once for each non-static global  variable  which  was
  1421.           defined. The "size" paremeter indicates the  number  of  BYTES  of
  1422.           memory to be reserved for that variable.
  1423.     
  1424.              The function "def_extern(symbol)" is called at the end  of  the
  1425.           compile, once for each  non-resolved  external  symbol  which  was
  1426.           defined. This routine should examine the type of  the  symbol  and
  1427.           output the appriopriate assembler directives to  allow  it  to  be
  1428.           referenced in another module.
  1429.     
  1430.              The "def_func(symbol, size)"  routine  is  called  to  start  a
  1431.           function definition. The "symbol" parameter is an index  into  the
  1432.           compiler symbol tables for the function entry being  defined.  The
  1433.           "size" parameter indicates how many  bytes  of  memory  should  be
  1434.           allocated on the stack for local variables.
  1435.     
  1436.              The "end_func()" routine is  called  to  terminate  a  function
  1437.           definition.  It  should  remove  anything  placed  on  the   stack
  1438.           (including the local variable space allocated by "def_func"),  and
  1439.           terminate the function with a "return" instruction.
  1440.     
  1441.              The "def_label(label)" function is called whenever the compiler
  1442.           wants to generate a label in the output file. Each label generated
  1443.           by the compiler is identified by a 16 bit unsigned number.  It  is
  1444.           up to the code generator to generate a unique label  suitable  for
  1445.           the target assembler.
  1446.     
  1447.              The "def_literal(*ptr, size)" function is called at the end  of
  1448.           the compile, just before non-static global symbols are  generated.
  1449.           This routine is given a pointer to the compiler's "literal  pool",
  1450.           which contains all  the  character  strings  occuring  during  the
  1451.           compilation. The "size" parameter indicates  how  many  characters
  1452.           are in the pool. This pool must be generated in the output file as
  1453.           a string of byte constants.
  1454.     
  1455.              The "call(token, value,  type,  clean)"  function  is  used  to
  1456.           generate  a  machine  language  subroutine  call  to  the   entity
  1457.           indicated by the "token, value & type" parameters (See later). The
  1458.           "clean" parameter indicates how many entries were pushed onto  the
  1459.           stack as arguments, which should be removed following the function
  1460.           call.  Note:  Since  stack  entries  are   TWO   bytes   in   most
  1461.           implementations, the "clean" value must be multiplied  by  two  to
  1462.           get the actual number of bytes to be removed from the stack.
  1463.     MICRO-C                                                          Page: 29
  1464.  
  1465.  
  1466.              The function "jump(label,  ljmp)"  is  called  to  generate  an
  1467.           unconditional jump instruction to the indicated compiler generated
  1468.           label. The "ljmp" flag will be set to zero if the jump  references
  1469.           code within the same expression from which it  is  generated,  and
  1470.           non-zero if one or more statements may occur between the jump  and
  1471.           the destination label. This allows  the  code  generator  to  take
  1472.           advantage of "short" jumps if they are available on the target.
  1473.     
  1474.              The function "jump_if(cond, label, ljmp) is called to  generate
  1475.           a conditional jump to a compiler generated label. The "cond" value
  1476.           indicates the condition: FALSE = Jump if accumulator is zero, TRUE
  1477.           = jump if accumulator is non-zero. Remaining  parameters  are  the
  1478.           same as above.
  1479.     
  1480.              The function "do_switch(label)" is  passed  the  address  of  a
  1481.           "switch" table, which contains 16  bit  entries,  and  is  of  the
  1482.           following format:
  1483.     
  1484.                         label-1, value-1, label-2, value-2, ....
  1485.                         label-n, value-n, 0, default_label
  1486.     
  1487.              This routine should search the table for the value currently in
  1488.           the accumulator, and if found, it  should  proceed  to  the  label
  1489.           associated with that value. If the value is not found  before  the
  1490.           end of the table is encountered (identified by a  label  value  of
  1491.           zero), execution should  proceed  at  the  address  identified  by
  1492.           "default_label".
  1493.     
  1494.              The "index_ptr(token, value, type)"  routine  should  load  the
  1495.           index register with the value  of  the  entity  indicated  by  the
  1496.           "token, value & type" parameters. This will always  be  a  16  bit
  1497.           wide quantity.
  1498.     
  1499.              The "index_adr(token, value, type)"  routine  should  load  the
  1500.           index register with the 16 bit address of the  symbol  represented
  1501.           by "token, value & type".
  1502.     
  1503.              The routine "expand(type)" is called following  the  evaluation
  1504.           of expressions in "return" and "switch" statements, and is used to
  1505.           insure that the result is a 16 bit value.
  1506.     
  1507.              The routine "accop(oper, type)" is  called  to  perform  a  "no
  1508.           operand" operation on the accumulator. See "compile.h" for a  list
  1509.           of these operations. The "type" passed indicates the type of value
  1510.           expected as a result.
  1511.     
  1512.              The routine "accval(oper, rtype, token, value, type)" is called
  1513.           to perform a "one  operand"  operation  on  the  accumulator.  See
  1514.           "compile.h" for a list of these operations. "rtype" indicates  the
  1515.           type of value expected as a result. "token",  "value"  and  "type"
  1516.           indicate  the  location  and  type  of  operand  which  is   being
  1517.           processed.
  1518.     MICRO-C                                                          Page: 30
  1519.  
  1520.  
  1521.           4.2.1 Notes on code generation
  1522.     
  1523.                 The meaning of the individual bits  in  the  16  bit  "type"
  1524.              value which is passed to many of the code generation  routines,
  1525.              is documented in the "compile.h" file.
  1526.     
  1527.                 The meaning of "token"  is  documented  in  the  "compile.h"
  1528.              file. For  each  type  of  "token",  "value"  has  a  different
  1529.              meaning:
  1530.     
  1531.                 Token           Meaning of "value"
  1532.                 ----------------------------------------------------------
  1533.                 NUMBER          The numeric value of the constant.
  1534.                 STRING          The offset into the literal pool.
  1535.                 LABEL           The value of the compiler generated label.
  1536.                 SYMBOL          Index into global symbol tables.
  1537.                 All others      Undefined.
  1538.     
  1539.                 When token is a SYMBOL, the "value" passed is used to  index
  1540.              into the global symbol tables (contained within  the  "compile"
  1541.              module) to determine information about the variable:
  1542.     
  1543.                 s_name[value]   - Name of symbol (up to SYMBOL_SIZE characters).
  1544.                 s_type[value]   - Type of symbol (bits defined in "compile.h").
  1545.                 s_index[value]  - Variable index:
  1546.                     Global:     Index indicates symbol was the n'th one defined.
  1547.                     Local:      Index is stack offset from def_func.
  1548.                     Argument:   Index is stack offset from last argument pushed.
  1549.     
  1550.                 When calculating the stack offset for  ARGUMENTs,  you  must
  1551.              add the number of bytes placed on the stack when  the  function
  1552.              was called. This  includes  the  local  variables,  the  return
  1553.              address, and any other values that "def_func" might push.
  1554.     
  1555.                 There are two popular ways of  providing  addressability  to
  1556.              local variables:
  1557.     
  1558.                 If the processor has many registers, you can reserve one  as
  1559.              a "base" pointer, and point it at the top of the stack when the
  1560.              function  is  entered.  This  allows  local  variables  to   be
  1561.              referenced as negative offsets from that "base"  register,  and
  1562.              arguments to be referenced as positive offsets  from  it.  This
  1563.              approach also allows the stack to  be  restored  directly  from
  1564.              this base  register  when  the  function  terminates.  See  the
  1565.              section on assembly language interfacing.
  1566.     
  1567.                 Another approach is to have the  code  generator  "remember"
  1568.              exactly how many bytes have been pushed onto  the  stack  since
  1569.              "def_func", and adjust the offsets it generates  based  on  the
  1570.              stack contents. This has  the  advantage  of  not  tying  up  a
  1571.              register.
  1572.     
  1573.                 It is the responsibility of the code generator to keep track
  1574.              of the validity  of  the  upper  8  bits  of  the  accumulator.
  1575.              Appropriate sign extension or clearing of  high  bits  must  be
  1576.              performed as necessary to convert signed and unsigned character
  1577.              values when 16 bit results when required.
  1578.     MICRO-C                                                          Page: 31
  1579.  
  1580.  
  1581.                 To improve the effiency of conditional statements, the  code
  1582.              generator should keep track of the validity of the "zero"  flag
  1583.              in  the  processor's  condition  code  register,  and  generate
  1584.              appropriate  "test"  instructions  only  if  necessary  when  a
  1585.              conditional jump is compiled.
  1586.     
  1587.                 For  processors  not  supporting   operations   with   stack
  1588.              contents, the "ON_STACK" and "ION_STACK" tokens may implemented
  1589.              by first popping the top of the  stack  into  a  register.  The
  1590.              "ISTACK_TOP" token is a special case, because  the  address  on
  1591.              the top of the stack must  not  be  lost.  This  token  may  be
  1592.              efficiently implemented, because "ISTACK_TOP" is only used  for
  1593.              read/write operations to  a  stacked  calculated  address.  For
  1594.              example:
  1595.     
  1596.                             array1[i] += array2[i];
  1597.     
  1598.                 This statement calculates the address of "array1[i]" (in the
  1599.              index register). Since the "index" register is  again  used  in
  1600.              calculating the address of "array2[i]", the first "index"  will
  1601.              be placed on the stack. Once the contents  of  "array2[i]"  are
  1602.              retrieved, it  will  be  added  using  "ISTACK_TOP",  and  then
  1603.              re-stored using "ION_STACK".
  1604.     
  1605.                 The "ISTACK_TOP" token may  thus  pop  the  address  into  a
  1606.              register, and set a flag indicating to the code generator  that
  1607.              the next "ION_STACK" token  is  to  go  through  that  register
  1608.              rather than the top of the stack. Note that since an arithmetic
  1609.              operation may be performed between the two references, you must
  1610.              not use a register which is  modified  in  code  generated  for
  1611.              arithmetic operations.
  1612.     
  1613.                 Refer to the sample code  generators  distributed  with  the
  1614.              compiler.
  1615.     
  1616.        4.3 The "compile" module
  1617.     
  1618.              The "compile" module  contains  the  main  statement  analyser,
  1619.           input  scanner,  expression  parser  and  symbol  table  managment
  1620.           routines for the MICRO-C compiler. This module is  common  to  all
  1621.           implementations, and should NOT require any  changes.  The  source
  1622.           code for this module is contained in the "compile.c" file on  your
  1623.           distribution diskette, and may be examined for  insight  into  the
  1624.           internal operation of the compiler.
  1625.     
  1626.              This module must be compiled and linked with your I/O and  code
  1627.           generation routines to  generate  a  complete  executable  MICRO-C
  1628.           compiler.
  1629.     
  1630.              To test your code generator,  the  file  "test.c"  is  provided
  1631.           which when compiled using the new compiler, performs a  number  of
  1632.           simple tests  to  verify  your  code  generator.  This  is  not  a
  1633.           comprehensive analysis, as  it  makes  no  assumptions  about  the
  1634.           processor, however, it provides a good indication that  your  code
  1635.           generator is on the right track.
  1636.     MICRO-C                                                          Page: 32
  1637.  
  1638.  
  1639.        4.4 Porting without an existing compiler
  1640.     
  1641.              If you have the MICRO-C  distribution  files,  but  no  running
  1642.           compiler, it is still possible to port  the  compiler,  using  the
  1643.           following steps:
  1644.     
  1645.           1) You must write the code generator and I/O routines  in  another
  1646.              language. Using assembly language is  preferable,  because  you
  1647.              can then follow the MICRO-C function calling  conventions  (See
  1648.              "Assembly Language Interface  under  "Advanced  Topics").  This
  1649.              allows you to use the same routines with the compiler later.
  1650.     
  1651.           2) The "genasm.c" program should then be re-written  in  the  same
  1652.              language as above. This should not be difficult, since it is  a
  1653.              fairly simple program.
  1654.     
  1655.           3) Link "genasm" with your code generator  and  I/O  routines,  to
  1656.              create the "genasm" utility which reads intermediate files  and
  1657.              produces assembly language output.
  1658.     
  1659.           4) The "intermediate"  file  for  the  main  "compile"  module  is
  1660.              provided in the file "compile.i". When this file  is  processed
  1661.              by "genasm", and the resultant file assembled,  you  will  have
  1662.              the "compile" module which may be  linked  with  the  "io"  and
  1663.              "code" modules to produce the final compiler.
  1664.     
  1665.        4.5 Porting without a linker
  1666.     
  1667.              It is possible to port MICRO-C using a system  which  does  not
  1668.           support a linker. To do this, you must concatinate all the  source
  1669.           files "compile.c", "code.c" and "io.c" into  one  large  file  (in
  1670.           that order), and compile them all as one program.
  1671.     
  1672.              When this is done, the ".h" include files need only be included
  1673.           once, and external definitions  of  variables  occuring  in  other
  1674.           source files should not  be  used.  The  source  programs  on  the
  1675.           distribution disk all contain conditional  compilation  statements
  1676.           (#ifndef), which only perform the necessary #include and  external
  1677.           definition statements when compiling as a single file.
  1678.     MICRO-C                                                          Page: 33
  1679.  
  1680.  
  1681.        4.6 Code Optimization
  1682.     
  1683.              The MICRO-C compiler performs the following machine independant
  1684.           optimizations of the output file:
  1685.     
  1686.           1) All constant expressions are evaluated  at  compile  time,  and
  1687.              expressed as a single constant value in the output code.
  1688.     
  1689.           2) Operations which are not sensitive to order (eg:  '+')  may  be
  1690.              reversed to take advantage of partial results  already  in  the
  1691.              accumulator.
  1692.     
  1693.           3) Redundant jumps as a result of "return" or  "break"  statements
  1694.              are suppressed.
  1695.     
  1696.           4) The sense of jumps in conditional statements are  reversed  for
  1697.              logically negated expressions, code for '!' is  only  generated
  1698.              if the value returned by that operator is actually used.
  1699.     
  1700.           5) Jumps between code generated within  a  single  expression  are
  1701.              flagged as "short".
  1702.     
  1703.              Although the MICRO-C compiler produces fairly  reasonable  code
  1704.           for the  processor  model  it  uses,  that  model  is  necessarily
  1705.           limited, in order that it might fit a  large  number  of  physical
  1706.           targets. There are  several  simple  optimizations  which  may  be
  1707.           peformed to further enhance the code generated by the compiler  in
  1708.           a specific implementation.
  1709.     
  1710.           4.6.1 Register Usage
  1711.     
  1712.                 MICRO-C assumes a single accumulator,  and  a  single  index
  1713.              register. Additional  terms  in  commplicated  expressions  are
  1714.              handled by placeing temporary results on the  processor  stack,
  1715.              and re-using those registers. All data placed on the  stack  is
  1716.              accessed on a "last in - first out" basis.
  1717.     
  1718.                 If the target processor has a  full  compliment  of  general
  1719.              purpose registers, an optimization may be performed  by  simply
  1720.              selecting another general purpose register as  the  accumulator
  1721.              or index register instead of placing the value  on  the  stack.
  1722.              The code generator must  keep  track  of  the  order  in  which
  1723.              registers are selected, and which register represents the "top"
  1724.              of the stack. If the number  of  values  "pushed"  exceeds  the
  1725.              number of available registers, the "oldest" register should  be
  1726.              placed on the stack, thereby allowing it to be re-used.
  1727.     MICRO-C                                                          Page: 34
  1728.  
  1729.  
  1730.           4.6.2 Jump Optimization
  1731.     
  1732.                 Although MICRO-C identifies jumps to instructions which span
  1733.              more than one expression as "long",  often  the  addresses  are
  1734.              close enough together that short jumps may  actually  be  used.
  1735.              This optimization is particularily useful for  processors  such
  1736.              as the 8086, which does not support "long"  conditional  jumps,
  1737.              and therefore must simulate them with a short conditional  jump
  1738.              of the opposite sense around a long unconditional jump.
  1739.     
  1740.           4.6.3 Redundant Load Elimination
  1741.     
  1742.                 Since  MICRO-C  evaluates  and  processes   each   statement
  1743.              individually, it  does  not  carry  partial  results  from  one
  1744.              statement to another.
  1745.     
  1746.                 Consider the following statements:
  1747.     
  1748.                                  a = x;
  1749.                                  b = a + 1;
  1750.     
  1751.                 MICRO-C generates the code:
  1752.     
  1753.                                  LOAD x
  1754.                                  STORE a
  1755.                                  LOAD a
  1756.                                  ADD 1
  1757.                                  STORE b
  1758.     
  1759.                 An optimization may be performed  by  recognizing  that  the
  1760.              second "load" instruction is redundant, and can be  eliminated.
  1761.              Note: A more efficent (but less readable)  way  of  coding  the
  1762.              above statements which would result in the latter code  without
  1763.              optimization is:
  1764.     
  1765.                                  b = (a = x) + 1;
  1766.     MICRO-C                                                          Page: 35
  1767.  
  1768.  
  1769.           4.6.4 Peephole Optimization
  1770.     
  1771.                 Consider the statement:
  1772.     
  1773.                                  a = *++ptr;
  1774.     
  1775.                 MICRO-C generates the code:
  1776.     
  1777.                                  LOAD ptr
  1778.                                  INCREMENT
  1779.                                  STORE ptr
  1780.                                  MOVE ACCUMULATOR TO INDEX
  1781.                                  LOAD [INDEX]
  1782.                                  STORE a
  1783.     
  1784.                 For a processor supporting  a  rich  set  of  direct  memory
  1785.              addressing modes, the above sequence can be shortened to:
  1786.     
  1787.                                  INCREMENT_MEMORY ptr
  1788.                                  LOAD [ptr]
  1789.                                  STORE a
  1790.     
  1791.                 One of the most  successful  techniques  of  optimizing  the
  1792.              output code is also one of the simplest.  Known  as  "peephole"
  1793.              optimization, the method consists of keeping a  window  of  the
  1794.              last few instructions generated,  and  scanning  the  list  for
  1795.              known patterns every time a new instruction is added to it.
  1796.     
  1797.                 As long as the instructions in the list at  least  partially
  1798.              match one or more  of  the  "predefined"  patterns,  additional
  1799.              instructions are collected  until  either  a  complete  pattern
  1800.              match occurs, or all known patterns are eliminated.
  1801.     
  1802.                 If no matches occur, the "oldest" instruction is written  to
  1803.              the output file, and the next one  becomes  the  first  in  the
  1804.              "window".
  1805.     
  1806.                 Whenever a pattern is discovered, it is replaced  by  a  new
  1807.              series of instructions which perform the same function, but  in
  1808.              a more efficent manner.
  1809.     
  1810.                 The new instruction sequences  are  replaced  on  the  list,
  1811.              which may then be  again  scanned,  allowing  further  possible
  1812.              reductions to be discovered.
  1813.     
  1814.                 Handling of labels in the "window" and  their  corresponding
  1815.              placement in the output file must be carefully done,  in  order
  1816.              to preserve the "logical" context of the original code.
  1817.     MICRO-C                                                          Page: 36
  1818.  
  1819.  
  1820.     5. THE MICRO-C PREPROCESSOR
  1821.     
  1822.           The MICRO-C Preprocessor is a source code filter,  which  provides
  1823.        greater capabilities than the preprocessor which is integral  to  the
  1824.        MICRO-C compiler. It has been implemented as a  stand  alone  utility
  1825.        program which processes the source code before it is compiled.
  1826.     
  1827.           Due to the higher complexity of  this  preprocessor,  it  operates
  1828.        slightly slower than the the integral MICRO-C preprocessor.  This  is
  1829.        mainly due to the fact that it reads each line from the file and then
  1830.        copies it to a new line while performing the macro  substution.  This
  1831.        is necessary since each macro may contain parameters  which  must  be
  1832.        replaced "on the fly" when it is referenced.
  1833.     
  1834.           The integral MICRO-C preprocessor is very FAST,  because  it  does
  1835.        not copy the input line. When it encounters a '#define'd  symbol,  it
  1836.        simply adjusts the input scanner pointer to point to  the  definition
  1837.        of that symbol.
  1838.     
  1839.           Keeping the enhanced preprocessor as a stand alone utility  allows
  1840.        you  to  choose  between  greater   MACRO   capability   and   faster
  1841.        compilation. It also allows the system to continue  to  run  on  very
  1842.        small hardware platforms.
  1843.     
  1844.           The additional capabilities of the enhanced preprocessor are:
  1845.     
  1846.             - Fully parameterized MACROs.
  1847.     
  1848.             - Fully nested conditionals
  1849.     
  1850.             - Ability to undefine MACRO symbols.
  1851.     
  1852.             - Library reference in include file names.
  1853.     MICRO-C                                                          Page: 37
  1854.  
  1855.  
  1856.        5.1 The MCP command
  1857.     
  1858.              The format of the MICRO-C Preprocessor command line is:
  1859.     
  1860.                     MCP [input_file] [output_file] [options]
  1861.     
  1862.              [input_file] is the name of  the  source  file  containing  'C'
  1863.           statements to read. If no filenames are given, MCP will read  from
  1864.           standard input.
  1865.     
  1866.              [output_file] is the name of the file to  write  the  processed
  1867.           source code to. If less than two filenames are specified, MCP will
  1868.           write to standard output.
  1869.     
  1870.           5.1.1 Command Line Options
  1871.     
  1872.                 MCP accepts the following command line [options]:
  1873.     
  1874.                 -c      - Instructs MCP to keep comments from  the input
  1875.                           file (except for those in '#' statements which
  1876.                           are always removed). Normally, MCP will remove
  1877.                           all comments.
  1878.     
  1879.                 l=path  - Defines the directory path which will be taken
  1880.                           to reference  "library"  files when  '<>'  are
  1881.                           used around an  '#include'  file name.  Unless
  1882.                           otherwise specified, the path defaults to:
  1883.                                         '/mc/include'
  1884.     
  1885.                 -q      - Instructs MCP to be quiet, and not display the
  1886.                           startup message when it is executed.
  1887.     MICRO-C                                                          Page: 38
  1888.  
  1889.  
  1890.        5.2 Preprocesor Commands
  1891.     
  1892.              The following commands are recognized by the MCP utility,  only
  1893.           if they occur at the beginning of the source file line:
  1894.     
  1895.           5.2.1 #define <name>(parameters) <replacement text>
  1896.     
  1897.                 Defines a global macro name which will be replaced with  the
  1898.              indicated <replacement text> wherever it occurs in  the  source
  1899.              file.
  1900.     
  1901.                 Macro  names  may  be  any  length,  and  may  contain   the
  1902.              characters 'a'-'z', 'A'-'Z', '0'-'9' and '_'.  Names  must  not
  1903.              begin with the characters '0'-'9'.
  1904.     
  1905.                 If the macro name is IMMEDIATELY followed by a list of up to
  1906.              10 parameter names contained in brackets, those parameter names
  1907.              will be substituted with parameters passed to the macro when it
  1908.              is referenced. Parameter names follow the same rules  as  macro
  1909.              names.
  1910.     
  1911.                      eg: #define min(a, b) (a < b ? a : b)
  1912.     
  1913.                 If any spaces exist between the macro name and  the  opening
  1914.              '(', the macro will not be  parameterized,  and  all  following
  1915.              text  (including  '('  and  ')')  will  be  entered  into   the
  1916.              definition.
  1917.     
  1918.           5.2.2 #undef <symbol>
  1919.     
  1920.                 Undefines the named macro symbol. further references to this
  1921.              symbol will not be replaced.
  1922.     
  1923.                 NOTE: With MCP, macro definitions operate on a STACK. IE: If
  1924.              you define a macro  symbol,  and  then  re-define  it  (without
  1925.              '#undef'ing it first), subsequently '#undef'ing it  will  cause
  1926.              it to revert to its  previous  definition.  A  second  '#undef'
  1927.              would then cause it to be completely undefined.
  1928.     
  1929.           5.2.3 #forget <symbol>
  1930.     
  1931.                 Similar  to  '#undef',  except  that  the  symbol  and   ALL
  1932.              SUBSEQUENTLY DEFINED SYMBOLS will be undefined.
  1933.     
  1934.                 Useful for releasing any local symbols (used only  within  a
  1935.              single include file).
  1936.     
  1937.                 For example:
  1938.     
  1939.                         #define GLOBAL "xxx"    /* first global symbol */
  1940.                             ...                 /* more globals */
  1941.                         #define LOCAL   "xxx"   /* first local symbol */
  1942.                             ...                 /* more locals */
  1943.                         /* body of include file goes here */
  1944.                         #forget LOCAL           /* release locals */
  1945.     MICRO-C                                                          Page: 39
  1946.  
  1947.  
  1948.           5.2.4 #ifdef <symbol>
  1949.     
  1950.                 Causes the following lines (up to '#else' of '#endif') to be
  1951.              processed and included in the source file  only  if  the  named
  1952.              symbol is defined as a macro.
  1953.     
  1954.           5.2.5 #ifndef <symbol>
  1955.     
  1956.                 Causes the following lines (up to '#else' of '#endif') to be
  1957.              processed and included in the source file  only  if  the  named
  1958.              symbol is NOT defined as a macro.
  1959.     
  1960.                 NOTE: '#ifdef/#ifndef#else/#endif' may be nested.
  1961.     
  1962.           5.2.6 #else
  1963.     
  1964.                 Toggles the state of the "if_flag", controlling  conditional
  1965.              processing. Only has effect in the highest level  of  suspended
  1966.              processing. IE: Nested conditionals will work properly.
  1967.     
  1968.                 If the previous  '#ifdef/#ifndef'  failed,  processing  will
  1969.              begin again following the '#else'.
  1970.     
  1971.                 If the previous '#ifdef/#ifndef' passed, processing will  be
  1972.              suspended until the '#endif' is encountered.
  1973.     
  1974.                 NOTE: Since '#else' acts as a toggle, it may be used outside
  1975.              of any '#ifdef/#ifndef' to unconditionally  suspend  processing
  1976.              up to the '#endif'.
  1977.     
  1978.           5.2.7 #endif
  1979.     
  1980.                 Resets  the  "if_flag"  controlling  conditionals,   causing
  1981.              processing to resume. Only has effect in the highest  level  of
  1982.              suspended  processing.  IE:  Nested  conditionals   will   work
  1983.              properly.
  1984.     MICRO-C                                                          Page: 40
  1985.  
  1986.  
  1987.           5.2.8 #include <filename>
  1988.     
  1989.                 Causes MCP to open tha named file and include  its  contents
  1990.              as part of the input source.
  1991.     
  1992.                 If the filename is contained within '"' characters, it  will
  1993.              be opened exactly as  specified,  and  (unless  it  contains  a
  1994.              directory path) will reference a file in the current directory.
  1995.     
  1996.                 If the filename is contained within the characters  '<'  and
  1997.              '>', it will be  prefixed  with  the  library  path  (See  'l='
  1998.              option), and will therefore reference a file  in  that  library
  1999.              directory. The default  library  directory  is  assumed  to  be
  2000.              '/mc/include'.
  2001.     
  2002.                 For example:
  2003.     
  2004.                         #include "header.h"     /* from current directory */
  2005.                         #include <stdio.h>      /* from library directory */
  2006.     
  2007.           5.2.9 #asm / #endasm
  2008.     
  2009.                 The  '#asm'  and  '#endasm'  statement  are   not   actually
  2010.              recognized by MCP. They are passed through unchanged,  allowing
  2011.              them to be recognized and acted upon by  the  integral  MICRO-C
  2012.              preprocessor.
  2013.     MICRO-C                                                          Page: 41
  2014.  
  2015.  
  2016.        5.3 Error messages
  2017.     
  2018.              When MCP detects an error during processing of an include file,
  2019.           it displays an error message,  which  is  preceeded  by  the  line
  2020.           numbers of the files in which the error occurs. If  more  than  10
  2021.           errors are encountered, MCP will terminate.
  2022.     
  2023.              The following error messages are reported by MCP:
  2024.     
  2025.           5.3.1 Cannot open include file
  2026.     
  2027.                 A '#include' statement on the  indicated  line  specified  a
  2028.              file which could not be opened for read.
  2029.     
  2030.           5.3.2 Invalid include file name
  2031.     
  2032.                 A '#include' statement on the  indicated  line  specified  a
  2033.              file  name  which  was  not  contained  within  '"'   or   '<>'
  2034.              characters.
  2035.     
  2036.           5.3.3 Invalid macro name
  2037.     
  2038.                 A '#define' statement on the indicated line contains a macro
  2039.              name which does not follow the name rules.
  2040.     
  2041.           5.3.4 Invalid macro parameter
  2042.     
  2043.                 A '#define' statement on the indicated line contains a macro
  2044.              parameter name which does not follow the name rules.
  2045.     
  2046.                 A reference to a macro does not have a proper ')'  character
  2047.              to terminate the parameter list.
  2048.     
  2049.           5.3.5 Too many errors
  2050.     
  2051.                 More  than  10  errors  has  been  encountered  and  MCP  is
  2052.              terminating.
  2053.     
  2054.           5.3.6 Too many maco definitions
  2055.     
  2056.                 MCP has encountered more '#define' statements  than  it  can
  2057.              handle.
  2058.     
  2059.           5.3.7 Too many macro parameters
  2060.     
  2061.                 A '#define' statement on the indicated line  specifies  more
  2062.              parameters parameters to the macro than MCP can handle.
  2063.     
  2064.           5.3.8 Too many include files
  2065.     
  2066.                 MCP has encountered more nested '#include'  statements  than
  2067.              it can handle.
  2068.     MICRO-C                                                          Page: 42
  2069.  
  2070.  
  2071.           5.3.9 Undefined macro
  2072.     
  2073.                 A '#undef' or '#forget'  statement  on  the  indicated  line
  2074.              references a macro name which has not been defined.
  2075.     
  2076.           5.3.10 Unterminated comment
  2077.     
  2078.                 The END OF FILE has  been  encountered  while  processing  a
  2079.              comment.
  2080.     
  2081.           5.3.11 Unterminated string
  2082.     
  2083.                 A quoted string string on the indicated line has no end.
  2084.     MICRO-C                                                          Page: 43
  2085.  
  2086.  
  2087.     6. THE MICRO-C OPTIMIZER
  2088.     
  2089.           The MICRO-C optimizer is an output code filter which examines  the
  2090.        assembly code produced by the compiler, recognizing known patterns of
  2091.        inefficent code (using the "peephole" technique), and  replaces  them
  2092.        with more optimal code  which  performs  the  same  function.  It  is
  2093.        entirely table driven, allowing it to be modified for  virtually  any
  2094.        processor.
  2095.     
  2096.           Due its many table lookup operations, the  optimizer  may  perform
  2097.        quite slowly when processing a large  file.  For  this  reason,  most
  2098.        people prefer not to optimize during the debugging of a program,  and
  2099.        utilize the optimizer only when creating the final copy.
  2100.     
  2101.        6.1 The MCO command
  2102.     
  2103.              The format of the MICRO-C Optimizer command line is:
  2104.     
  2105.                     MCO [input_file] [output_file] [options]
  2106.     
  2107.              [input_file] is the name of the source file containing assembly
  2108.           statements to read. If no filenames are given, MCO will read  from
  2109.           standard input.
  2110.     
  2111.              [output_file] is the name of the file to  write  the  optimized
  2112.           assembly code to. If less than two filenames  are  specified,  MCO
  2113.           will write to standard output.
  2114.     
  2115.           6.1.1 Command Line Options
  2116.     
  2117.                 MCO accepts the following command line [options]:
  2118.     
  2119.                 -d      - Instructs MCO to produce a  'debug' display on
  2120.                           standard output showing the source code  which
  2121.                           it is removing and replacing in the input file.
  2122.                           NOTE: If you do not specify an explict  output
  2123.                                 file, you will get the debug  statements
  2124.                                 intermixed with the  optimized  code  on
  2125.                                 standard output.
  2126.     
  2127.                 -q      - Instructs MCO to be quiet, and not display the
  2128.                           startup message when it is executed.
  2129.     MICRO-C                                                          Page: 44
  2130.  
  2131.  
  2132.        6.2 Porting to a new processor
  2133.     
  2134.              The MICRO-C Optimizer is completely table driven, and should be
  2135.           fairly easy to port to a new processor.
  2136.     
  2137.              The peephole optimization table  is  called  'peep_table',  and
  2138.           consists of two  sequential  character  string  entries  for  each
  2139.           optimization.
  2140.     
  2141.              The first is the "take" entry, and  represents  an  instruction
  2142.           sequence which (if found) is to be removed from the  output  file.
  2143.           The second  is  the  "give"  entry,  and  defines  a  sequence  of
  2144.           instructions to be placed in the output file at that  point.  NOTE
  2145.           that due to the way the optimizer removes and replaces instruction
  2146.           in the circular "peephole" buffer, the instructions in the  "give"
  2147.           entry ARE CODED IN REVERSE ORDER.
  2148.     
  2149.              Characters in the "take" entry  with  the  high  bit  set  (ge:
  2150.           '\200','\201') are special characters which represent any variable
  2151.           string which may occur in the instruction sequence,  and  will  be
  2152.           replaced with the same string wherever that  character  occurs  in
  2153.           the "give" entry. If  the  same  special  character  (eg:  '\200')
  2154.           occurs more than once  in  the  "take"  entry,  the  corresponding
  2155.           strings must be exactly the same or else the entire sequence  will
  2156.           not be matched.
  2157.     
  2158.              The processor will stop scanning  a  variable  string  when  it
  2159.           encounters the character which  immediately  follows  the  special
  2160.           character in the "take" entry, or at the end of the input line.
  2161.     
  2162.              The  manifest  SYMBOLS  defines  how  many  different   special
  2163.           characters are allowed in a peephole entry. You must not  use  any
  2164.           special characters which have  a  value  greater  than  ('\200'  +
  2165.           SYMBOLS - 1).
  2166.     MICRO-C                                                          Page: 45
  2167.  
  2168.  
  2169.     7. LIBRARY FUNCTIONS
  2170.     
  2171.           The MICRO-C distribution disk includes a file  called  "library.c"
  2172.        which contains the 'C' source code for a number of  useful  "library"
  2173.        functions. These routines may be also be used as "example"  programs,
  2174.        providing insight into MICRO-C programming techniques.
  2175.     
  2176.           All functions except for the lowest level I/O routines  are  coded
  2177.        in 'C', and should compile on any MICRO-C system. Note that some  low
  2178.        level functions in the library (such as "fputs") are written  in  'C'
  2179.        using still lower level routines (in this case "putc"). Although this
  2180.        makes the library highly portable and reduces the number of  routines
  2181.        you have to re-write for a specific system,  the  resultant  function
  2182.        will be less efficent than one  which  directly  uses  the  operating
  2183.        system services.
  2184.     
  2185.           If you are implementing MICRO-C an a small system  and  intend  to
  2186.        use it for serious programming, I strongly recommend that you re-code
  2187.        all of the low level library functions in assembly language.
  2188.     
  2189.           Note that since library routines are often used,  in  applications
  2190.        where code size and execution speed are of primary importance, it may
  2191.        be desirable to recode some or all of the other library  routines  in
  2192.        assembly language as well.
  2193.     
  2194.           For those who intend to make only casual use of  MICRO-C,  or  who
  2195.        wish to experiment with it simply for the  learning  experience,  the
  2196.        'C' versions of the low level library functions should be  more  than
  2197.        sufficient.
  2198.     
  2199.           The following routines are available in "library.c" at this time:
  2200.     ABORT                                                             ABORT
  2201.     
  2202.     
  2203.     
  2204.     PROTOTYPE:
  2205.     
  2206.         abort(char *message)
  2207.     
  2208.     
  2209.     ARGUMENTS:
  2210.     
  2211.         message - Pointer to message to display
  2212.     
  2213.     
  2214.     RETURN VALUE:
  2215.     
  2216.         N/A - Function never returns.
  2217.     
  2218.     
  2219.     DESCRIPTION:
  2220.     
  2221.           This function writes the string passed as an argument to  standard
  2222.        error, and then terminates the program with a  return  code  of  '-1'
  2223.        (Indicating general  failure).  This  provides  a  simple  method  of
  2224.        terminating a program on an error condition with a message explaining
  2225.        why.
  2226.     
  2227.     
  2228.     EXAMPLES:
  2229.     
  2230.         abort("Invalid operand\n");
  2231.     ABS                                                                 ABS
  2232.     
  2233.     
  2234.     
  2235.     PROTOTYPE:
  2236.     
  2237.         int abs(int number)
  2238.     
  2239.     
  2240.     ARGUMENTS:
  2241.     
  2242.         number  - Any integer value
  2243.     
  2244.     
  2245.     RETURN VALUE:
  2246.     
  2247.         The absolute value of "number".
  2248.     
  2249.     
  2250.     DESCRIPTION:
  2251.     
  2252.           The "abs" function returns the absolute value of the argument.  If
  2253.        "number" is a positive value, it is returned unchanged. If  negative,
  2254.        the negate of that value is returned (giving a positive result).
  2255.     
  2256.     
  2257.     EXAMPLES:
  2258.     
  2259.         difference = abs(value1 - value2);
  2260.     ATOI                                                               ATOI
  2261.     
  2262.     
  2263.     
  2264.     PROTOTYPE:
  2265.     
  2266.         int atoi(char *string)
  2267.     
  2268.     
  2269.     ARGUMENTS:
  2270.     
  2271.         string  - Pointer to a string containing a decimal number
  2272.     
  2273.     
  2274.     RETURN VALUE:
  2275.     
  2276.         16 bit integer value.
  2277.     
  2278.     
  2279.     DESCRIPTION:
  2280.     
  2281.           The "atoi" function converts an ASCII string containing  a  signed
  2282.        decimal number (-32768 to 32767) to a 16 bit value which is returned.
  2283.        An unsigned number of the range (0 to 65535) may also  be  used,  and
  2284.        the result if assigned to an "unsigned" variable will be correct.
  2285.     
  2286.     
  2287.     EXAMPLES:
  2288.     
  2289.         value = atoi("1234");
  2290.         value = atoi("-1");
  2291.     CONCAT                                                           CONCAT
  2292.     
  2293.     
  2294.     
  2295.     PROTOTYPE:
  2296.     
  2297.         register concat(char *dest, char *source, ...)
  2298.     
  2299.     
  2300.     ARGUMENTS:
  2301.     
  2302.         dest    - Pointer to destination string
  2303.         source  - Pointer to source string
  2304.         ...     - Additional sources may be given
  2305.     
  2306.     
  2307.     RETURN VALUE:
  2308.     
  2309.         None
  2310.     
  2311.     
  2312.     DESCRIPTION:
  2313.     
  2314.           The "concat" function concatinates the given source  strings  into
  2315.        one destination string. The destination string must be  large  enough
  2316.        to hold all of the source strings plus the string  terminator  (zero)
  2317.        byte. No value is returned.
  2318.     
  2319.           NOTE: This function uses a variable number of arguments, and  must
  2320.        be declared as "register".
  2321.     
  2322.     
  2323.     EXAMPLES:
  2324.     
  2325.         concat(filename,"/tmp/", input_name, 0);
  2326.     COPY                                                               COPY
  2327.     
  2328.     
  2329.     
  2330.     PROTOTYPE:
  2331.     
  2332.         copy(char *dest, char *source, unsigned size)
  2333.     
  2334.     
  2335.     ARGUMENTS:
  2336.     
  2337.         dest    - Pointer to the destination
  2338.         source  - Pointer to the souce
  2339.         size    - Number of bytes to copy
  2340.     
  2341.     
  2342.     RETURN VALUE:
  2343.     
  2344.         None
  2345.     
  2346.     
  2347.     DESCRIPTION:
  2348.     
  2349.           The "copy" function will copy the specified number of  bytes  from
  2350.        the source to the destination.
  2351.     
  2352.     
  2353.     EXAMPLES:
  2354.     
  2355.         copy(buffer1, buffer2, 256);
  2356.     EXIT                                                               EXIT
  2357.     
  2358.     
  2359.     
  2360.     PROTOTYPE:
  2361.     
  2362.         exit(int rc);
  2363.     
  2364.     
  2365.     ARGUMENTS:
  2366.     
  2367.         rc      - Termination return code.
  2368.     
  2369.     
  2370.     RETURN VALUE:
  2371.     
  2372.         N/A - Function never returns.
  2373.     
  2374.     
  2375.     DESCRIPTION:
  2376.     
  2377.           This function terminates the execution of the program and passes a
  2378.        specific return code back to the  operating  system.  A  return  code
  2379.        value of zero is used  to  indicate  successful  program  completion.
  2380.        Non-zero return code values may be used to indicate a particular type
  2381.        of failure. A value of '-1' is often used to indicate a  non-specific
  2382.        failure. Note that  the  "rc"  value  is  very  system  specific,  in
  2383.        particular, some systems support only 8 bit return codes,  so  values
  2384.        which are greater than 255 should be avoided.
  2385.     
  2386.     
  2387.     EXAMPLES:
  2388.     
  2389.         exit(0);        /* success */
  2390.         exit(-1);       /* failure */
  2391.     FCLOSE                                                           FCLOSE
  2392.     
  2393.     
  2394.     
  2395.     PROTOTYPE:
  2396.     
  2397.         fclose(FILE *fp);
  2398.     
  2399.     
  2400.     ARGUMENTS:
  2401.     
  2402.         fp      - File pointer to an open file
  2403.     
  2404.     
  2405.     RETURN VALUE:
  2406.     
  2407.         None
  2408.     
  2409.     
  2410.     DESCRIPTION:
  2411.     
  2412.           This function closes a file  which  was  previously  opened  using
  2413.        "fopen". The I/O buffer space used by the file is  released.  In  the
  2414.        case of a file open for write ('w'), the last disk buffer is  flushed
  2415.        and written to disk.
  2416.     
  2417.     
  2418.     EXAMPLES:
  2419.     
  2420.         fclose(fp);
  2421.     FGET                                                               FGET
  2422.     
  2423.     
  2424.     
  2425.     PROTOTYPE:
  2426.     
  2427.         fget(char *buffer, int size, FILE *fp)
  2428.     
  2429.     
  2430.     ARGUMENTS:
  2431.     
  2432.         buffer  - Pointer to buffer to receive data
  2433.         size    - Number of bytes to read
  2434.         fp      - File pointer to an input file
  2435.     
  2436.     
  2437.     RETURN VALUE:
  2438.     
  2439.         Number of bytes read from file.
  2440.     
  2441.     
  2442.     DESCRIPTION:
  2443.     
  2444.           This function reads a block of data from a file and places  it  in
  2445.        memory at the address of "buffer". Data is read in "raw"  form,  with
  2446.        no interpretation of "newline" characters etc. If the number of bytes
  2447.        returned is less than the number of bytes requested, either  the  end
  2448.        of the file was encountered or an error condition occured  (in  which
  2449.        case the value will be zero).
  2450.     
  2451.     
  2452.     EXAMPLES:
  2453.     
  2454.         fget(block, 512, input_fp);
  2455.     FGETS                                                             FGETS
  2456.     
  2457.     
  2458.     
  2459.     PROTOTYPE:
  2460.     
  2461.         char *fgets(char *buffer, int size, FILE *fp)
  2462.     
  2463.     
  2464.     ARGUMENTS:
  2465.     
  2466.         buffer  - Pointer to string to receive line
  2467.         size    - Maximum size of line to read
  2468.         fp      - File pointer to an input file
  2469.     
  2470.     
  2471.     RETURN VALUE:
  2472.     
  2473.         Pointer to "buffer", or 0 if end of file.
  2474.     
  2475.     
  2476.     DESCRIPTION:
  2477.     
  2478.           The "fgets" function reads characters  from  the  specified  input
  2479.        file, and places them in the character  buffer  until  one  of  three
  2480.        things happens:
  2481.     
  2482.           1) A NEWLINE character is encountered.
  2483.     
  2484.           2) The END of the file is encountered.
  2485.     
  2486.           3) The limit of "size" character is read.
  2487.     
  2488.           The strng is terminated with the standard NULL (00) character. The
  2489.        trailing NEWLINE '\n' character is NOT included in the output buffer.
  2490.     
  2491.     
  2492.     EXAMPLES:
  2493.     
  2494.         fgets(input_line, 80, input_file);
  2495.     FOPEN                                                             FOPEN
  2496.     
  2497.     
  2498.     
  2499.     PROTOTYPE:
  2500.     
  2501.         FILE *fopen(char *filename, char *options)
  2502.     
  2503.     
  2504.     ARGUMENTS:
  2505.     
  2506.         filename- Name of the file to open
  2507.         options - String containing open options, valid modes are:
  2508.                     "r"  - Open file for read
  2509.                     "w"  - Open file for write
  2510.                     "rw" - Open for read/write update.
  2511.                     "wa" - Open for write & append
  2512.     
  2513.     
  2514.     RETURN VALUE:
  2515.     
  2516.         File pointer to the file buffer for the open file.
  2517.         Zero (0) if file could not be opened.
  2518.     
  2519.     
  2520.     DESCRIPTION:
  2521.     
  2522.           This function opens a  file  for  input  ('r')  or  output  ('w'),
  2523.        allowing subsequent I/O operations to read or write the file.
  2524.     
  2525.     
  2526.     EXAMPLES:
  2527.     
  2528.         fp = fopen("input_file", "r");
  2529.     FPRINTF                                                         FPRINTF
  2530.     
  2531.     
  2532.     
  2533.     PROTOTYPE:
  2534.     
  2535.         register fprintf(FILE *fp, char *format, arg, ...)
  2536.     
  2537.     
  2538.     ARGUMENTS:
  2539.     
  2540.         fp      - File pointer to an output file
  2541.         format  - Pointer to format string
  2542.         arg     - Argument as determined by format string
  2543.         ...     - Additional arguments may be required
  2544.     
  2545.     
  2546.     RETURN VALUE:
  2547.     
  2548.         None
  2549.     
  2550.     
  2551.     DESCRIPTION:
  2552.     
  2553.           This routine performs a formatted print to  a  file  specified  by
  2554.        "fp". The "format" string is written to the file with  the  arguments
  2555.        substituted for special "conversion  characters".  These  "conversion
  2556.        characters" are identified by a precedding '%', and may be one of the
  2557.        following:
  2558.     
  2559.                     b       - Binary number.
  2560.                     c       - Character.
  2561.                     d       - Decimal (signed) number.
  2562.                     o       - Octal number.
  2563.                     s       - String.
  2564.                     u       - Unsigned decimal number.
  2565.                     x       - Hexidecimal number.
  2566.                     %       - A single percent sign (No argument used).
  2567.     
  2568.           A numeric "field width" specifier may be placed in between the '%'
  2569.        and the conversion character, in which case the value will be  output
  2570.        in a field of that width. If the "field width" is a negative  number,
  2571.        the output will be left justified in the field, otherwise it is right
  2572.        justified. If the field width contains a leading '0', then the output
  2573.        field will be padded with zero's, otherwise spaces are used.
  2574.     
  2575.           If no "field width" is given, the output  is  free  format,  using
  2576.        only as much space as required.
  2577.     
  2578.           NOTE: This function uses a variable number of arguments, and  must
  2579.        be declared as "register".
  2580.     
  2581.     
  2582.     EXAMPLES:
  2583.     
  2584.         fprintf(stderr,"Filename='%s'\n", filename);
  2585.         fprintf(stdout,"Address=%04x\n", address);
  2586.         fprintf(outfile,"Amount: $%3u.%02u\n", amount / 100, amount % 100);
  2587.     FPUT                                                               FPUT
  2588.     
  2589.     
  2590.     
  2591.     PROTOTYPE:
  2592.     
  2593.         fput(char *block, int size, FILE *fp)
  2594.     
  2595.     
  2596.     ARGUMENTS:
  2597.     
  2598.         block   - Pointer to a block of data to write
  2599.         size    - Number of bytes to write
  2600.         fp      - File pointer to an output file
  2601.     
  2602.     
  2603.     RETURN VALUE:
  2604.     
  2605.         The number of bytes written.
  2606.     
  2607.     
  2608.     DESCRIPTION:
  2609.     
  2610.           This function writes a block of data to the  indicated  file  from
  2611.        memory at the specified address. Data is written in "raw" form,  with
  2612.        no translations of "newline" characters etc. If the value returned is
  2613.        less than the value of the "size" parameter, some error condition has
  2614.        occured (Such as disk full).
  2615.     
  2616.     
  2617.     EXAMPLES:
  2618.     
  2619.         if(fput(buffer, 100, fp) < 100)
  2620.             abort("File write error\n");
  2621.     FPUTS                                                             FPUTS
  2622.     
  2623.     
  2624.     
  2625.     PROTOTYPE:
  2626.     
  2627.         fputs(char *string, FILE *fp)
  2628.     
  2629.     
  2630.     ARGUMENTS:
  2631.     
  2632.         string  - Pointer to a character string
  2633.         fp      - FIle pointer to output file
  2634.     
  2635.     
  2636.     RETURN VALUE:
  2637.     
  2638.         None
  2639.     
  2640.     
  2641.     DESCRIPTION:
  2642.     
  2643.           The "fputs" function writes the specified string to the  indicated
  2644.        output file. The zero terminating the string is NOT written.
  2645.     
  2646.     
  2647.     EXAMPLES:
  2648.     
  2649.         fputs("Text message", output_file);
  2650.     GETC                                                               GETC
  2651.     
  2652.     
  2653.     
  2654.     PROTOTYPE:
  2655.     
  2656.         int getc(FILE *fp)
  2657.     
  2658.     
  2659.     ARGUMENTS:
  2660.     
  2661.         fp      - File pointer to an input file
  2662.     
  2663.     
  2664.     RETURN VALUE:
  2665.     
  2666.         Value of a character read from the file (0-255).
  2667.         -1 if end of file or an error condition occurs.
  2668.     
  2669.     
  2670.     DESCRIPTION:
  2671.     
  2672.           This function reads a single character from  an  input  file,  and
  2673.        returns it as a positive value in the range of 0 to 255.  A  full  16
  2674.        bit value is returned, allowing the  end  of  file  condition  to  be
  2675.        distinct from the character value 255.
  2676.     
  2677.     
  2678.     EXAMPLES:
  2679.     
  2680.         if((c = getc(input_file)) < 0)
  2681.             abort("End of file encountered\n");
  2682.     ISALPHA                                                         ISALPHA
  2683.     
  2684.     
  2685.     
  2686.     PROTOTYPE:
  2687.     
  2688.         int isalpha(char c)
  2689.     
  2690.     
  2691.     ARGUMENTS:
  2692.     
  2693.         c       - Any character value
  2694.     
  2695.     
  2696.     RETURN VALUE:
  2697.     
  2698.         1 if 'c' is alphabetic
  2699.         0 if 'c' is not alphabetic
  2700.     
  2701.     
  2702.     DESCRIPTION:
  2703.     
  2704.           Returns  TRUE  (1)  if  the  passed  character  'c'  is  an  ASCII
  2705.        alphabetic letter in either upper or lower case, otherwise FALSE  (0)
  2706.        is returned.
  2707.     
  2708.     
  2709.     EXAMPLES:
  2710.     
  2711.         flag = isalpha(input_char);
  2712.     ISDIGIT                                                         ISDIGIT
  2713.     
  2714.     
  2715.     
  2716.     PROTOTYPE:
  2717.     
  2718.         int isdigit(char c)
  2719.     
  2720.     
  2721.     ARGUMENTS:
  2722.     
  2723.         c       - Any character value
  2724.     
  2725.     
  2726.     RETURN VALUE:
  2727.     
  2728.         1 if 'c' is numeric
  2729.         0 if 'c' is not numeric
  2730.     
  2731.     
  2732.     DESCRIPTION:
  2733.     
  2734.           Returns TRUE (1) is the passed character 'c'  is  as  ASCII  digit
  2735.        ('0'-'9'), otherwise FALSE (0) is returned.
  2736.     
  2737.     
  2738.     EXAMPLES:
  2739.     
  2740.         value = 0;
  2741.         while(isdigit(*ptr))
  2742.             value = (value * 10) + (*ptr++ - '0');
  2743.     ISLOWER                                                         ISLOWER
  2744.     
  2745.     
  2746.     
  2747.     PROTOTYPE:
  2748.     
  2749.         int islower(char c)
  2750.     
  2751.     
  2752.     ARGUMENTS:
  2753.     
  2754.         c       - Any character value
  2755.     
  2756.     
  2757.     RETURN VALUE:
  2758.     
  2759.         1 if 'c' is lower case alphabetic
  2760.         0 if 'c' is not lower case alphabetic
  2761.     
  2762.     
  2763.     DESCRIPTION:
  2764.     
  2765.           Returns  TRUE  (1)  if  the  passed  character  'c'  is  an  ASCII
  2766.        alphabetic letter of lower case, otherwise FALSE (0) is returned.
  2767.     
  2768.     
  2769.     EXAMPLES:
  2770.     
  2771.         flag = islower(input_char);
  2772.     ISSPACE                                                         ISSPACE
  2773.     
  2774.     
  2775.     
  2776.     PROTOTYPE:
  2777.     
  2778.         int isspace(char c)
  2779.     
  2780.     
  2781.     ARGUMENTS:
  2782.     
  2783.         c       - Any character value
  2784.     
  2785.     
  2786.     RETURN VALUE:
  2787.     
  2788.         1 if 'c' is a space character (space, tab or newline)
  2789.         0 if 'c' is not a space character
  2790.     
  2791.     
  2792.     DESCRIPTION:
  2793.     
  2794.           Returns TRUE (1) if the passed character 'c' is one  of  a  space,
  2795.        tab or newline, otherwise FALSE (0) is returned.
  2796.     
  2797.     
  2798.     EXAMPLES:
  2799.     
  2800.         while(isspace(*ptr))
  2801.             ++ptr;
  2802.     ISUPPER                                                         ISUPPER
  2803.     
  2804.     
  2805.     
  2806.     PROTOTYPE:
  2807.     
  2808.         int isupper(char c)
  2809.     
  2810.     
  2811.     ARGUMENTS:
  2812.     
  2813.         c       - Any character value
  2814.     
  2815.     
  2816.     RETURN VALUE:
  2817.     
  2818.         1 if 'c' is upper case alphabetic
  2819.         0 if 'c' is not upper case alphabetic
  2820.     
  2821.     
  2822.     DESCRIPTION:
  2823.     
  2824.           Returns  TRUE  (1)  if  the  passed  character  'c'  is  an  ASCII
  2825.        alphabetic letter of upper case, otherwise FALSE (0) is returned.
  2826.     
  2827.     
  2828.     EXAMPLES:
  2829.     
  2830.         flag = isupper(input_char);
  2831.     MAX                                                                 MAX
  2832.     
  2833.     
  2834.     
  2835.     PROTOTYPE:
  2836.     
  2837.         int max(int value1, int value2)
  2838.     
  2839.     
  2840.     ARGUMENTS:
  2841.     
  2842.         value1  - Any integer value
  2843.         value2  - Any integer value
  2844.     
  2845.     
  2846.     RETURN VALUE:
  2847.     
  2848.         The greater of "value1" or "value2".
  2849.     
  2850.     
  2851.     DESCRIPTION:
  2852.     
  2853.           The "max" function returns the higher of its two argument values.
  2854.     
  2855.     
  2856.     EXAMPLES:
  2857.     
  2858.         biggest = max(a, b);
  2859.     MIN                                                                 MIN
  2860.     
  2861.     
  2862.     
  2863.     PROTOTYPE:
  2864.     
  2865.         int min(int value1, int value2)
  2866.     
  2867.     
  2868.     ARGUMENTS:
  2869.     
  2870.         value1  - Any integer value
  2871.         value2  - Any integer value
  2872.     
  2873.     
  2874.     RETURN VALUE:
  2875.     
  2876.         The smaller of "value1" or "value2".
  2877.     
  2878.     
  2879.     DESCRIPTION:
  2880.     
  2881.           The "min" function returns the lower of its two argument values.
  2882.     
  2883.     
  2884.     EXAMPLES:
  2885.     
  2886.         least = min(a, b);
  2887.     NARGS                                                             NARGS
  2888.     
  2889.     
  2890.     
  2891.     PROTOTYPE:
  2892.     
  2893.         int nargs()
  2894.     
  2895.     
  2896.     ARGUMENTS:
  2897.     
  2898.         None
  2899.     
  2900.     
  2901.     RETURN VALUE:
  2902.     
  2903.         The number of arguments passed to the calling function
  2904.     
  2905.     
  2906.     DESCRIPTION:
  2907.     
  2908.           Returns the number of arguments passed to a  "register"  function.
  2909.        NOTE:  When  calling  a  "register"  function,  MICRO-C   loads   the
  2910.        accumulator with the number of arguments just prior  to  calling  the
  2911.        function. This "nargs" routine is  simply  a  null  definition  which
  2912.        returns with the same value in the accumulator as was there  when  it
  2913.        was called. Therefore "nargs" MUST BE  THE  FIRST  ARITHMETIC  ENTITY
  2914.        EVALUATED WITHIN  THE  REGISTER  FUNCTION  or  the  contents  of  the
  2915.        accumulator will be lost. Some examples of "register" definitions and
  2916.        the use of "nargs" may be found in the "library.c" source code.
  2917.     
  2918.     
  2919.     EXAMPLES:
  2920.     
  2921.         first_arg = nargs() * 2 + &arguments;
  2922.     PRINTF                                                           PRINTF
  2923.     
  2924.     
  2925.     
  2926.     PROTOTYPE:
  2927.     
  2928.         register printf(char *format, arg1, arg2, ...)
  2929.     
  2930.     
  2931.     ARGUMENTS:
  2932.     
  2933.         format  - Pointer to format string
  2934.         arg     - Argument as determined by format string
  2935.         ...     - Additional arguments may be required
  2936.     
  2937.     
  2938.     RETURN VALUE:
  2939.     
  2940.         None
  2941.     
  2942.     
  2943.     DESCRIPTION:
  2944.     
  2945.           The "printf" routine performs a formatted  print  to  the  console
  2946.        device. The "format" string  is  written  to  the  console  with  the
  2947.        arguments substituted for special "conversion characters".
  2948.     
  2949.           See "fprintf" for more information on format strings.
  2950.     
  2951.           NOTE: This function uses a variable number of arguments, and  must
  2952.        be declared as "register".
  2953.     
  2954.     
  2955.     EXAMPLES:
  2956.     
  2957.         printf("Hello world!!!\n");
  2958.         printf("File '%s', has %u lines\n", filename, num_lines);
  2959.     PUTC                                                               PUTC
  2960.     
  2961.     
  2962.     
  2963.     PROTOTYPE:
  2964.     
  2965.         putc(char c, FILE *fp)
  2966.     
  2967.     
  2968.     ARGUMENTS:
  2969.     
  2970.         c       - Any character value
  2971.         fp      - File pointer to an output file
  2972.     
  2973.     
  2974.     RETURN VALUE:
  2975.     
  2976.         None
  2977.     
  2978.     
  2979.     DECRIPTION:
  2980.     
  2981.           This function writes the character 'c' to the  file  indicated  by
  2982.        "fp". The "newline" (\n) character will be translated  into  whatever
  2983.        character(s) are required by the operating system to separate records
  2984.        in the file.
  2985.     
  2986.     
  2987.     EXAMPLES:
  2988.     
  2989.         putc('*', fp);
  2990.         putc('\n', stderr);
  2991.     SPRINTF                                                         SPRINTF
  2992.     
  2993.     
  2994.     
  2995.     PROTOTYPE:
  2996.     
  2997.         register sprintf(char *string, char *format, arg1, arg2, ...)
  2998.     
  2999.     
  3000.     ARGUMENTS:
  3001.     
  3002.         dest    - Pointer to destination string
  3003.         format  - Pointer to format string
  3004.         arg     - Argument as determined by format string
  3005.         ...     - Additional arguments may be required
  3006.     
  3007.     
  3008.     RETURN VALUE:
  3009.     
  3010.         None
  3011.     
  3012.     
  3013.     DESCRIPTION:
  3014.     
  3015.           The "sprintf" routine performs a formatted print to  a  string  in
  3016.        memory. The "format" string is written to the destination string with
  3017.        the arguments substituted for special "conversion characters".
  3018.     
  3019.           See "fprintf" for more information on format strings.
  3020.     
  3021.           NOTE: This function uses a variable number of arguments, and  must
  3022.        be declared as "register".
  3023.     
  3024.     
  3025.     EXAMPLES:
  3026.     
  3027.         sprintf(header_file, "/lib/%s.h", header_name);
  3028.     STRCAT                                                           STRCAT
  3029.     
  3030.     
  3031.     
  3032.     PROTOTYPE:
  3033.     
  3034.         strcat(char *dest, *source)
  3035.     
  3036.     
  3037.     ARGUMENTS:
  3038.     
  3039.         dest    - Pointer to destination string
  3040.         source  - Pointer to source string
  3041.     
  3042.     
  3043.     RETURN VALUE:
  3044.     
  3045.         None
  3046.     
  3047.     
  3048.     DESCRIPTION:
  3049.     
  3050.           This function concatinates the source string onto the tail of  the
  3051.        destination string. The destination string must be  large  enough  to
  3052.        hold the entire contents of both strings.
  3053.     
  3054.     
  3055.     EXAMPLES:
  3056.     
  3057.         strcat(program_name, ".c");
  3058.     STRCMP                                                           STRCMP
  3059.     
  3060.     
  3061.     
  3062.     PROTOTYPE:
  3063.     
  3064.         strcmp(char *string1, char *string2)
  3065.     
  3066.     
  3067.     ARGUMENTS:
  3068.     
  3069.         string1 - Pointer to first string
  3070.         string2 - Pointer to second string
  3071.     
  3072.     
  3073.     RETURN VALUE:
  3074.     
  3075.         0   - String match exactly
  3076.         1   - String1 is greater than string2
  3077.         -1  - String2 is greater than string1
  3078.     
  3079.     
  3080.     DESCRIPTION:
  3081.     
  3082.           This function compares two strings character by character. If  the
  3083.        two strings are identical, a zero  (0)  is  returned.  If  the  first
  3084.        string is greater than the second (as far as ASCII is  concerned),  a
  3085.        one (1) is returned. If the second string is greater, a negative  one
  3086.        (-1) is returned.
  3087.     
  3088.     
  3089.     EXAMPLES:
  3090.     
  3091.         if(!strcmp(command, "quit"))
  3092.             exit(0);
  3093.     STRCPY                                                           STRCPY
  3094.     
  3095.     
  3096.     
  3097.     PROTOTYPE:
  3098.     
  3099.         strcpy(char *dest, char *source)
  3100.     
  3101.     
  3102.     ARGUMENTS:
  3103.     
  3104.         dest    - Pointer to destination string
  3105.         souce   - Pointer to source string
  3106.     
  3107.     
  3108.     RETURN VALUE:
  3109.     
  3110.         None
  3111.     
  3112.     
  3113.     DESCRIPTION:
  3114.     
  3115.           This function copies the source string to the destination  string.
  3116.        All data is copied up to and including the zero byte which terminates
  3117.        the string. The destination string must be large enough to  hold  the
  3118.        entire source.
  3119.     
  3120.     
  3121.     EXAMPLES:
  3122.     
  3123.         strcpy(filename, argv[1]);
  3124.     STRLEN                                                           STRLEN
  3125.     
  3126.     
  3127.     
  3128.     PROTOTYPE:
  3129.     
  3130.         int strlen(char *string)
  3131.     
  3132.     
  3133.     ARGUMENTS:
  3134.     
  3135.         string  - Pointer to a character string
  3136.     
  3137.     
  3138.     RETURN VALUE:
  3139.     
  3140.         The length of the string
  3141.     
  3142.     
  3143.     DECRIPTION:
  3144.     
  3145.           Returns the length in character of the passed string.  The  length
  3146.        does not include the zero byte which terminates the string.
  3147.     
  3148.     
  3149.     EXAMPLES:
  3150.     
  3151.         length = strlen(command);
  3152.     TOLOWER                                                         TOLOWER
  3153.     
  3154.     
  3155.     
  3156.     PROTOTYPE:
  3157.     
  3158.         char tolower(char c)
  3159.     
  3160.     
  3161.     ARGUMENTS:
  3162.     
  3163.         c   - Any character value
  3164.     
  3165.     
  3166.     RETURN VALUE:
  3167.     
  3168.         The value of 'c', converted to lower case
  3169.     
  3170.     
  3171.     DESCRIPTION:
  3172.     
  3173.           Returns the value of 'c' converted to lower case. If 'c' is not  a
  3174.        letter of upper case, no change is made, and the  original  value  of
  3175.        'c' is returned.
  3176.     
  3177.     
  3178.     EXAMPLES:
  3179.     
  3180.         input_char = tolower(getc(stdin));
  3181.     TOUPPER                                                         TOUPPER
  3182.     
  3183.     
  3184.     
  3185.     PROTOTYPE:
  3186.     
  3187.         char toupper(char c)
  3188.     
  3189.     
  3190.     ARGUMENTS:
  3191.     
  3192.         c   - Any character value
  3193.     
  3194.     
  3195.     RETURN VALUE:
  3196.     
  3197.         The value of 'c', converted to upper case
  3198.     
  3199.     
  3200.     DESCRIPTION:
  3201.     
  3202.           Returns the value of 'c' converted to upper case. If 'c' is not  a
  3203.        letter of lower case, no change is made, and the  original  value  of
  3204.        'c' is returned.
  3205.     
  3206.     
  3207.     EXAMPLES:
  3208.     
  3209.         putc(toupper(output_char), stdout);
  3210.     ZERO                                                               ZERO
  3211.     
  3212.     
  3213.     
  3214.     PROTOTYPE:
  3215.     
  3216.         zero(char *block, unsigned size)
  3217.     
  3218.     
  3219.     ARGUMENTS:
  3220.     
  3221.         block   - Pointer to a block of memory
  3222.         size    - Number of bytes to zero
  3223.     
  3224.     
  3225.     RETURN VALUE:
  3226.     
  3227.         None
  3228.     
  3229.     
  3230.     DESCRIPTION:
  3231.     
  3232.           Zeros a block of memory beginning  at  the  pointer  "block",  for
  3233.        "size" bytes.
  3234.     
  3235.     
  3236.     EXAMPLES:
  3237.     
  3238.         zero(buffer, 100);
  3239.  
  3240.  
  3241.  
  3242.                                     MICRO-C
  3243.  
  3244.                                TABLE OF CONTENTS
  3245.  
  3246.  
  3247.                                                                          Page
  3248.  
  3249.      1. INTRODUCTION                                                        1
  3250.  
  3251.         1.1 Code Portability                                                2
  3252.         1.2 Compiler Portability                                            2
  3253.         1.3 The MCC command                                                 3
  3254.         1.4 Command files                                                   3
  3255.  
  3256.      2. THE MICRO-C PROGRAMMING LANGUAGE                                    4
  3257.  
  3258.         2.1 Constants                                                       4
  3259.         2.2 Symbols                                                         4
  3260.         2.3 Arrays & Pointers                                               7
  3261.         2.4 Functions                                                       7
  3262.         2.5 Control Structures                                              8
  3263.         2.6 Expression Operators                                           10
  3264.         2.7 Preprocessor Commands                                          12
  3265.         2.8 Error Messages                                                 13
  3266.         2.9 Quirks                                                         17
  3267.  
  3268.      3. ADVANCED TOPICS                                                    19
  3269.  
  3270.         3.1 Conversion Rules                                               19
  3271.         3.2 Assembly Language Interface                                    20
  3272.         3.3 Compiling for ROM                                              23
  3273.  
  3274.      4. PORTING THE COMPILER                                               24
  3275.  
  3276.         4.1 The "io" module                                                25
  3277.         4.2 The "code" module                                              27
  3278.         4.3 The "compile" module                                           31
  3279.         4.4 Porting without an existing compiler                           32
  3280.         4.5 Porting without a linker                                       32
  3281.         4.6 Code Optimization                                              33
  3282.  
  3283.      5. THE MICRO-C PREPROCESSOR                                           36
  3284.  
  3285.         5.1 The MCP command                                                37
  3286.         5.2 Preprocesor Commands                                           38
  3287.         5.3 Error messages                                                 41
  3288.  
  3289.      6. THE MICRO-C OPTIMIZER                                              43
  3290.  
  3291.         6.1 The MCO command                                                43
  3292.         6.2 Porting to a new processor                                     44
  3293.  
  3294.      7. LIBRARY FUNCTIONS                                                  45
  3295.  
  3296.