CCNA32 (alpha code) is a small-c for gnu Linux. It will take small-c source and generate NASM -f elf source code, 32-bit. This is a departure from the -f bin code generation of the prior versions of small-c. CCNA32.C is compiled by GCC, its makefile contents is shown in the beginning of the C source. There is quite a list of warnings given by GCC, but there shouldn't be any errors reported. GCC doesn't officially support K&R C anymore. This version is 0r5, and is designated Alpha Code because it won't compile itself without a segmentation fault. The fault seems to be near the first '%include'.

The example, tst_1.c, represents your small-c code project. It compiles with CCNA32 in a terminal session (command line) and the result is tst_1.nsm assembly. The tst_1.nsm is assembled with the current version of NASM for linux resulting in an elf object file. There are three auxilliary assembler files required for the assembly; PROLOG.NSM, EPILOG.NSM, and IO_CLIB.NSM, which take care of houskeeping matters. IO_CLIB.NSM holds interface code to access the C Library functions resident in memory as Shared Objects. IO_CLIB.NSM covers those functions required for compiling small-c itself, plus a few extra, so it is not a full mapping to all LIBC functions. It shows the pattern to use for other CLIB functions (to map to LIBC functions) as you develop a need for them. The final object file; tst_1.o then needs to be linked to the Shared Object to generate the final executable: tst_1. This is done thusly: ld --dynamic-linker /lib/ -lc -o tst_1 tst_1.o

Note: many of the new constructs in CCNA32.C are commented out awaiting further integration, and testing. The main thrust was the development of IO_CLIB, whose short list of functions map to the corresponding external C functions available by dynamic linking to the shared object; file.

The Small-c compiler program source CCNA32.C, and its makefile for GCC.

For your small-c code project, these files are required: PROLOG.NSM, EPILOG.NSM, and IO_CLIB.NSM. The PROLOG.NSM and EPILOG.NSM setup the sections with ELF in mind. PROLOG sets up the ESP, defines the start symbol as main for your main(), calls your main(), handles the return from your main(). EPILOG.NSM defines the stack area, includes IO_CLIB.NSM, aligns the ends of .text and .data sections to paragraph boundries. These need to be present in the current working directory of CCNA32, along with your small-c code project. The NASM output of the CCNA32 compilation of your small-c code generates the directives to include these files, automatically, for you.

As an example, tst_1.c is given. The processfile() was cribbed from ccna32 itself to test file I/O. CCNA32 is run from the Terminal (commandline) and the output file is designated as tst_1.nsm, while the input file is given as tst_1.c, like this, which shows the compiling step, the assembly step, the linking step, and the execution step. So the assembler output is assembled by NASM using the terminal utility (the command line). This is easiest done using a nasm make file. Here is the one for the tst_1.nsm example, tst_1.mak, which also gives a listing file, tst_1.lst.

12:43 PM 10/30/2011