| 1 |
65 |
motilito |
Samll-C compiler adapted for embedded systems by Moti Litcochevski.
|
| 2 |
|
|
(February 20, 2012)
|
| 3 |
|
|
|
| 4 |
|
|
This compiler is an adapted version of the C80DOS compiler found on
|
| 5 |
|
|
http://www.cpm.z80.de/small_c.html.
|
| 6 |
|
|
|
| 7 |
|
|
After downloading the compiler I tried to generate some code for my FPGA SOC
|
| 8 |
|
|
using the light8080 CPU. The generated assembler code presented a few issues:
|
| 9 |
|
|
|
| 10 |
|
|
1. The compiler operates in interactive mode requesting the user to enter
|
| 11 |
|
|
filenames step by step. This is very inconvenient when compiling over and over
|
| 12 |
|
|
again.
|
| 13 |
|
|
2. The generated assembly code did not compile using my preferred AS80 assembler.
|
| 14 |
|
|
Although other assemblers are available, they are not free to be used for all
|
| 15 |
|
|
purposes.
|
| 16 |
|
|
3. The stack pointer was initialized to some constant value.
|
| 17 |
|
|
4. Some coding extras where missing. For example, defining IO ports for CPU
|
| 18 |
|
|
peripherals (see below).
|
| 19 |
|
|
|
| 20 |
|
|
The compiler version presented here provides some improvements to the above
|
| 21 |
|
|
issues:
|
| 22 |
|
|
|
| 23 |
|
|
1. Main routine was changed to enable command line operation of the compiler.
|
| 24 |
|
|
For command line options just run the compiler without any input options.
|
| 25 |
|
|
2. Assembly code was changed to the syntax used by the Z80. This enables the
|
| 26 |
|
|
output assembly file to be compiled using the AS80 tool.
|
| 27 |
|
|
3. Stack pointer initial value may be specified in the command line options.
|
| 28 |
|
|
4. Supporting line comments "//". this is a must for me.
|
| 29 |
|
|
5. Support for hexadecimal values defined with "0x" prefix.
|
| 30 |
|
|
6. Defining IO ports using the following syntax:
|
| 31 |
|
|
// value in brackets is the port address
|
| 32 |
|
|
port (128) UDATA;
|
| 33 |
|
|
Address may be entered as hexadecimal value.
|
| 34 |
|
|
7. Support for global variable init values either as strings or list.
|
| 35 |
|
|
For example:
|
| 36 |
|
|
// string init value
|
| 37 |
|
|
char tstring[10] = "Hello";
|
| 38 |
|
|
// value list init value
|
| 39 |
|
|
int tint[10] = {1,2,3,4,5,6,7,8,9,10};
|
| 40 |
|
|
|
| 41 |
|
|
Note that one of the program source file must include the "c80.lib" assembler file
|
| 42 |
|
|
which defines the library assembler functions used by the compiler. Currently all
|
| 43 |
|
|
functions will be added to the output file even if not used. This will increase the
|
| 44 |
|
|
size of the program memory by about 300 bytes.
|
| 45 |
|
|
|
| 46 |
|
|
Features that are missing from the current release:
|
| 47 |
|
|
1. Add "#ifdef" macro statements.
|
| 48 |
|
|
2. Include only the library functions used by the program.
|
| 49 |
|
|
|
| 50 |
|
|
Hope you find this application helpful,
|
| 51 |
|
|
Moti
|