home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 162_01 / readmore.doc < prev    next >
Text File  |  1985-08-21  |  5KB  |  129 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.                Mchip80     -   Release 1.2, Feb 86
  7.  
  8.  
  9.     I now believe that some Mchip80 users will have difficulty in
  10.    certain situations that were not covered in a practical way in the
  11.    original documentation. Last year when I decided that Mchip80 and its
  12.    documentation was ready for release, I had personally reached a stage of
  13.    keen awareness of the C/80 compiler's style and habits in creating an
  14.    assembly (.MAC) file from the C source. It is now apparent that this
  15.    awareness is necessary for all Mchip80 users, and some may need these
  16.    helpful suggestions.
  17.  
  18.     C/80 will initialize a float at every opportunity in a program,
  19.    right up to the last line. The original documentation was intended to
  20.    convey this meaning, and also to cover float constants, which are now
  21.    declared illegal for use with Mchip80. Here is an example of illegal
  22.    usage:
  23.  
  24.    #define    FCONSTA 123.4
  25.    float    fvar1,fvar2,pow();
  26.    main() {
  27.        fvar1 = pow(FCONSTA,fvar2);
  28.  
  29.         Here are two examples of pseudo float constants that are acceptable
  30.    with Mchip80. The first example is when the constant has a fraction part,
  31.    is in exponential notation, or for any other reason requires the function
  32.    atof(), Mchip80 version.
  33.  
  34.    char    fconsta[] = "123.4";
  35.    float    fvar1,fvar2,fconv,atof(),pow()
  36.    main() {
  37.        fvar2 = pow((fconv = atof(fconsta)),fvar1);
  38.  
  39.         The second example is when the constant value has no fraction, ie.,
  40.    can be expressed as an integer or long, and type conversion can do the
  41.    job.
  42.  
  43.    int    n;
  44.    float    fconsta;
  45.    main() {
  46.        fconsta = n =123;
  47.  
  48.         Both examples result in float variables that can be used as substite
  49.    constants, until they are written over with some other data. A great
  50.    awareness tool is the compiler '-t' switch, which can be useful on a
  51.    dummy "situation" program. The following program is 'unreal', having no
  52.    input or output, and is created solely for a '-t' switch exercise, and
  53.    resides on file 'specimen.c'.
  54.  
  55.    float    pow();    /* returns a float, says nothing about parameters */
  56.    float    fvar1,fvar2;
  57.    main() {
  58.        fvar2 = pow(123.4,fvar1);
  59.    }
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.         Use C/80 configured for floats and longs, with this command line:
  74.  
  75.    c -t specimen=specimen
  76.  
  77.         As promised in the Toolworks documentation, the compiler delivers a
  78.    .MAC file with all the source lines from 'specimen.c' at the appropriate
  79.    places, set up as comments. Print a hard copy of specimen.mac, put it
  80.    aside and read some more of this.
  81.  
  82.         You can also use the '-t' switch exercise on one of your real
  83.    programs, and I suggest color coding the .MAC printout for visual clarity
  84.    and pattern detection. You will need four to six different coloured felt
  85.    tip highlighters. Your first impression right now might be here comes a
  86.    tedious and childish task, but give it a try if Mchip80 does strange
  87.    things to your program. First use blue on all the comment lines from the
  88.    source file, to push them into the background. Put red on all RET
  89.    instructions, and there won't be many of them. Select either yellow or
  90.    green for the CALL instructions. Then treat every PUSH and POP
  91.    instruction to the same color, perhaps orange. It is starting to get
  92.    interesting, because a pattern is showing. C/80 uses the stack before and
  93.    after calling a function. Read more about it in the Toolworks
  94.    documentation.
  95.  
  96.         The most interesting lines are now in vivid black and white. Find
  97.    the segments where the program is handling floats or longs, it doesn't
  98.    matter which. Draw boxes around these segments in a color of your choice.
  99.    There should be CALLs to subroutines named 'slong' and 'llong', which are
  100.    in Mathpak, and which copy 32 bit variables between memory and registers
  101.    BC and DE. Mchip80 has no problem with 'slong' and 'llong', and is in
  102.    fact totally dependent on them.
  103.  
  104.         Look again for another situation inside the float/long boxes, where
  105.    numbers are loaded "immediate" (instruction LXI) into registers BC and
  106.    DE, and where 'slong' and 'llong' are absent. Here the C/80 compiler has
  107.    created these numbers and initialized a float or a long. If a float
  108.    variable received this treatment, the original program has to be changed
  109.    before it will work with Mchip80. You can see this undesirable situation
  110.    on the hard copy of 'specimen.mac' printed earlier. In a second exercise,
  111.    change the file 'specimen.c', by replacing 123.4 with fvar2, and do the
  112.    '-t' switch exercise again. This version is correct for Mchip80.
  113.  
  114.         The '-t' switch exercise is a great tool for exploring the interface
  115.    between C/80 and Mchip80, and after a little more use and experience, you
  116.    can almost phase it out.
  117. 
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.