home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / compiler / small_c / byte_sc / readme.doc < prev    next >
Encoding:
Text File  |  1988-06-23  |  8.6 KB  |  279 lines

  1.  
  2. 6-23-88, Peter Nelson
  3.  
  4.  
  5. This is the newly revised small-c compiler by BYTE magazine.
  6. The original small-c compiler was written for a CP/M system by 
  7. J.E. Hendrix (what! Jimmy Hendrix is still alive and writing
  8. compilers now!).  This new version is much improved.  You can read
  9. all about this new small-c compiler in the June, 1988 issue of BYTE
  10. magazine.
  11.  
  12. The .ARC file I received from BYTE did not include the CLIB.LIB function
  13. library, so I re-created it.  All the source code for the compiler is
  14. included here, but the only files you really need to use the small-c
  15. compiler are:
  16.  
  17.  
  18. CC86.EXE     The compiler
  19. STDIO.H      Definitions to be included in your 'C' program
  20. CLIB.LIB     The function library
  21.  
  22. EPILOG.H     Required for the assembler
  23. PROLOG.H     Required for the assembler
  24.  
  25. **MASM.EXE** Not included in this .ARC file - the Microsoft assembler
  26. **LINK.EXE** Not included in this .ARC file - the Microsoft linker 
  27.  
  28.  
  29. The compiler produces a .MAC file.  This file must be compiled by the
  30. Microsoft assembler, MASM.EXE, into .OBJ form.  The .OBJ file must be
  31. linked, using LINK.EXE, with CLIB.LIB to create the .EXE file.
  32.  
  33. I wrote a sample program, HELLO.C (what else of course), and compiled
  34. and linked it using the method described above.  It is included in
  35. this .ARC file.  One interesting problem: the original version of
  36. HELLO.C did not have a return(0) statement as the last line.  This
  37. compiled, assembled, and linked properly, but when executed printed
  38. the message 'error in .exe file.'  Adding return(0) as the last line
  39. solved the problem.
  40.  
  41. For other examples of programs written in small-c, dowload the file
  42. SCBENCH.ARC.  In it I have placed the source code for all of BYTE 
  43. magazine's NEW benchmark programs.  The compiled .EXE programs are
  44. also included.  Please read the June, 1988 issue of BYTE magazine
  45. for more information about the benchmark programs.  Basically
  46. speaking, these are the only benchmarks that really work.  The others
  47. are all seriously flawed, even the old BYTE magazine benchmarks!
  48.  
  49. Note:  I found that to successfully compile the library with the
  50. Microsoft assembler, I needed to use the /MX option.  This option 
  51. specifies that all external and public names are case sensitive, but
  52. all internal names are insensitive to upper or lower case.  You may
  53. find it necessary to use this option when compiling your own programs.
  54.  
  55. What follows is the original text of the README.DOC file as it came
  56. from BYTE magazine.  Have fun and learn 'C'!
  57.  
  58. Finis, Mongo
  59.  
  60.  
  61. ----------------------------------------------------------------------
  62.  
  63.  
  64. BYTE SMALL-C Version 1.0
  65.  
  66. Welcome:
  67.  
  68. You should find on this disk (or, in this archive) all the files you need
  69. to get started with BYTE Small-C.  Of course, I'm presuming that you have
  70. a copy of MASM and LINK around, since BYTE Small-C emits assembly-language
  71. source.  (I don't know whether or not the output is CHASM-compatible, and
  72. I'm CERTAIN it's not Optasm-compatible.  However, a little work with the
  73. conditional branches in the CC4*.C files should fix that.)
  74.  
  75. You should keep a few things in mind:
  76. 1) This is NOT an optimizing compiler.  It THINKS it is...I left the peephole
  77. optimizing routine -- peephole() -- alive, but it doesn't do anything.  The
  78. staging buffer is passed through unmodified, and here's where you I-live-to-
  79. optimize gangbusters can go hog wild.  I'd like to see the results.
  80.  
  81. 2) This version is 8088-compatible.  An 80386 version will follow shortly.
  82.  
  83. 3) We'll do our best to let you know of any bug fixes via Bix and in the
  84. magazine, but this is NOT a supported product.  We've put it in the public
  85. domain so that you can take it in whatever direction you choose.
  86.  
  87. 4) If you create any worthwhile programs in BYTE Small-C, we ask that you
  88. give conspicuous credit to "those who have gone before."  Ron Cain, J.E.
  89. Hendrix, L.E. Payne, and me -- R. E. Grehan.  (If you ever use the
  90. Mac version, don't forget Steve Williams.)
  91.  
  92. GETTING GOING
  93.  
  94. If you're just anxious to compile stuff, I've included a working executable
  95. of the compiler -- CC86.EXE.  Let's say you want to compile a file called
  96. "hello.c".  The commands you enter are:
  97.    CC86 HELLO.C
  98.    MASM HELLO.MAC;;
  99.    LINK HELLO   (and when the linker asks for .LIB files, give it
  100.                  CLIB.LIB)
  101.  
  102. HELLO.EXE will be created, and you're off and running.  Make sure
  103. PROLOG.H and EPILOG.H are available when you do the MASM.  These
  104. files contain segment info that HELLO.MAC needs.  (I'll be many of
  105. you see the CP/M origins of this stuff now.... ".MAC" instead of
  106. ".ASM".  Well, if that bothers you, modify the compiler.)
  107.  
  108. TIDBITS
  109.  
  110. * ASSEMBLY LANGUAGE:  You can drop into inline assembly language at any time
  111. with the #asm...#endasm construct.  Usually, I do this within entire
  112. functions, like:
  113.  
  114.   func(x,y)
  115.   int x,y;
  116.   {
  117.    #asm
  118.      .....assembly language code....
  119.    #endasm
  120.   }
  121. If you do this, keep one rule in mind: ALWAYS ALWAYS MAKE CERTAIN THE CX
  122. REGISTER IS CLEARED (ZERO) WHEN YOU LEAVE YOUR ROUTINE.  This is critical
  123. for the logical operations to work properly.  Otherwise, you can use whatever
  124. register you want (be careful with the SP, of course.)
  125.  
  126. * CALLING CONVENTIONS: All arguments are transferred on the stack in 16-bit
  127. form.  Arguments are pushed in left-to-right order, and the "topmost" entry
  128. on the stack is the return address.  You should leave the return value in
  129. the BX register.  An example might make this clearer:
  130.  
  131.  fadd2(a,b)    /* Add a and b, return result */
  132.  int a,b;
  133.  {
  134.  #asm
  135.     MOV BP,SP        /* Get stack pointer in BP */
  136.     MOV AX,2[BP]    /* Get b value */
  137.     MOV BX,4[BP]        /* Get a value */
  138.     ADD BX,AX           /* Add, result in BX */
  139.  #endasm
  140.  }
  141.  
  142. Also, unless you define NOCCARGC, a called function will receive an
  143. argument count in the AL register. (This is how printf() knows how many
  144. arguments it receives.)
  145.  
  146. * THE LIBRARY.  It would be impossible for me to go through a detailed
  147. description of all the library routines and what they do.  You should be
  148. able to get a good idea by reading the code itself.  Most adhere to the
  149. routines outlined in J.E. Hendrix's article "A New Library for Small-C".
  150. (You can find this reprinted in DR. DOOB'S TOOLBOOK OF C -- see the
  151. references at the end of this file.)
  152.  
  153. The big differences occur in the fileio routines, (cseek, fread, fwrite,
  154. ctell, etc.)
  155.  
  156. Following is a list of the library routines.  You can use your word
  157. processor to cut-and-paste this list into a batch file if you want to
  158. recreate the library CLIB.LIB.  I've also included a file for rebuilding
  159. the library -- LIBMAKE.TXT.  You can hand LIBMAKE.TXT to Microsoft's
  160. library manager (LIB).  Note that there are a couple of machine-language
  161. files (CALL.MAC, CEND.MAC -- used in by the system library) that you'll
  162. have to pass through MASM first.
  163.  
  164. A determined programmer could probably make some substantial improvements
  165. in the execution of library routines by simply recoding most of them
  166. in assembly language.  I'd like to see the results if you do this.
  167.  
  168. Library routine files:
  169.  
  170.  ABS.C
  171.  ATOI.C
  172.  ATOIB.C
  173.  AVAIL.C
  174.  CALLOC.C
  175.  CLEARERR.C
  176.  CSEEK.C
  177.  CSYSLIB.C
  178.  CTELL.C
  179.  DTOI.C
  180.  EXIT.C
  181.  FCLOSE.C
  182.  FEOF.C
  183.  FERROR.C
  184.  FGETC.C
  185.  FGETS.C
  186.  FOPEN.C
  187.  FPRINTF.C
  188.  FPUTC.C
  189.  FPUTS.C
  190.  FREAD.C
  191.  FREE.C
  192.  FREOPEN.C
  193.  FSCANF.C
  194.  FWRITE.C
  195.  GETARG.C
  196.  GETCHAR.C
  197.  ISALNUM.C
  198.  ISALPHA.C
  199.  ISASCII.C
  200.  ISATTY.C
  201.  ISCNTRL.C
  202.  ISCONS.C
  203.  ISDIGIT.C
  204.  ISGRAPH.C
  205.  ISLOWER.C
  206.  ISPRINT.C
  207.  ISPUNCT.C
  208.  ISSPACE.C
  209.  ISUPPER.C
  210.  ISXDIGIT.C
  211.  ITOA.C
  212.  ITOAB.C
  213.  ITOD.C
  214.  ITOO.C
  215.  ITOU.C
  216.  ITOX.C
  217.  LEFT.C
  218.  LEXCMP.C
  219.  MALLOC.C
  220.  OTOI.C
  221.  PAD.C
  222.  POLL.C
  223.  PUTCHAR.C
  224.  PUTS.C
  225.  RENAME.C
  226.  REVERSE.C
  227.  REWIND.C
  228.  SIGN.C
  229.  STRCAT.C
  230.  STRCHR.C
  231.  STRCMP.C
  232.  STRCPY.C
  233.  STRLEN.C
  234.  STRNCAT.C
  235.  STRNCMP.C
  236.  STRNCPY.C
  237.  STRRCHR.C
  238.  TOASCII.C
  239.  TOLOWER.C
  240.  TOUPPER.C
  241.  UNGETC.C
  242.  UNLINK.C
  243.  UTOI.C
  244.  XTOI.C
  245.  
  246.  
  247. Of course, the Small-C compiler itself is in files:
  248.  
  249. CC*.C
  250.  
  251.  
  252. FINALLY:
  253.  
  254. You'll probably get a better picture of Small-C if you locate the BYTE
  255. benchmark programs and examine the code there (not that those programs
  256. are any lustrous programming examples).  Particularly if you're interested
  257. in doing floating-point stuff, you should look for SCFMXX.C, the floating-
  258. point support files.  There are also support routines for most of the
  259. video adapters in the VIDEO benchmark routines.
  260.  
  261. Good luck.  Let me know what you think of all this.
  262.  
  263. --Rick Grehan
  264. BYTE Magazine
  265. Bix: rick_g
  266. Compuserve: 76224,13
  267.  
  268. REFERENCES
  269.  
  270. Hendrix, J.E.  The Small-C Handbook.  Reston, VA: Reston Publishing
  271. Company, 1984.
  272.  
  273. Dr. Dobb's Toolbook of C. New York, NY: Prentice-Hall, 1986.
  274.  
  275. Williams, Steve. Programming the Macintosh in Assembly Language.
  276. Berkeley, CA: Sybex, 1986.
  277.  
  278.  
  279.