ELFC
A C compiler for a CDP1802 microcomputer running Elf/OS or Mini/DOS
Install / Use
/learn @fourstix/ELFCREADME
ELFC
A C compiler for a CDP1802 based microcomputer running Elf/OS or Mini/DOS. ElfC is based on SubC written by Nils M Holms.
Installation
- Unzip the file elfc_r350.zip into the desired directory
- Copy the file
hello.cinto the directory. - Use the command elfc hello.c to compile the
hello.ctohello.elfos - Transfer the
hello.elfosfile to a microcomputer running Elf/OS or Mini/DOS. - Make the file executable using the chmod +x hello.elfos command
- Run the command hello.elfos to view the "Hello, World!" message
Design Goals
- Use the Asm/02 assembler and the Link/02 linker to produce CDP1802 binary code to run as an Elf/OS or Mini/DOS program
- Create a library based on Mike Riley's Library/02 standard library.
- Target both Elf/OS and Mini/DOS as a platform.
- Target Windows and Linux as the development platform (cross-compiler)
- Use an expression stack similar to the one implemented in Mike Riley's Fortran/02 program.
- Minimize changes to basic SubC compiler code and prefer changes to the code generation and library code functions.
- Implement the code generation functions first, migrate to the latest version of SubC and then work on implementing the C libraries.
- Extend the SubC code to cover additional C keywords and functions.
Release 1
This version is based on the SubC book version, 2nd Ed. described in the book Practical Compiler Construction by Nils M Holms.
I strongly recommend reading Nils's book. Practical Compiler Construction is a very good guide in explaining the theory behind the SubC compiler as well as describing the compiler's code. The second edition can be ordered as a paperback or pdf ebook file from Lulu press.
In Release 1 the code generation functions for Elf/OS and Mini/DOS have all been implemented. The arithmetic and logical operators have all been implemented and tested.
Release 2
This release migrates the code base to the current Experimental SubC version so that the code generator can include structures, unions and typedefs.
This release supports some basic code optimization as described in the book Practical Compiler Construction by Nils M Holms
The compiler supports the Asm/02 and Link/02 linker better, and included files and libraries are better organized.
The C runtime module crt0 now holds the start-up code for the program. The start up code now pushes the expected command line arguments for main onto the stack (int argc and char **argv) and then calls the main function.
An additional compiler option -L will compile and assemble Elf/OS (Min/iDOS) library modules from C files.
The stdlib, stdio, ctype, and string C libraries are supported as described in the book Practical Compiler Construction by Nils M Holms.
-
The C libraries are created from C files using the ElfC (
-L) library compile option. -
The header files use
#pragmastatements so the libraries link properly.
More information about unsupported library functions and header files can be found on the ELFC Detailed Information page. Information about ElfC internals can be found on the ELFC Internal Information page.
Release 2.5
This release adds an implementation of the C time library to ElfC, and a compiler option -N to compile without linking the C stdlib and stdio libraries.
More information about the time library functions and header files can be found on the ELFC Detailed Information page. Information about ElfC internals can be found on the ELFC Internal Information page.
Release 2.1
This release passes all the functional tests from the Experimental version of SubC. No new function was added to this release, only a few minor issues were fixed in this release. The functional test cases are included in this release.
Version 2
-
Version 2 implements the code generation functions required to compile a C file and assemble the resulting CDP1802 assembly and link code files into a binary program for the Elf/OS (Mini/DOS) operating system.
-
The assembler Asm/02 and linker Link/02 are now invoked with the same path as the compiler. The C library files and header files are located in the same manner, so that the preprocessor commands
#include <header.h>and#include "header.h"work as expected. -
Version 2 extends the library of arithmetic and variable functions based on the 16-bit standard library Library/02 to manipulate values on an expression stack.
-
This version implements the changes to the book compiler code contained in the latest current Experimental version of SubC.
-
The peep-hole code optimizations are all implemented except for the 386 assembly code Type Synthesis optimizations which have no equivalents available in 1802 assembly code. In the discussion RISC vs CISC on page 362 of Practical Compiler Construction, Nils M Holm covers this topic in more detail.
-
In addition to these optimizations, jump optimizations and push / pop optimizations were added that are specific to 1802 assembly code. Constant folding and AST trees are supported as in the Experimental SubC code.
-
The
asmstatement passes a string literal directly into the generated assembly file. -
The
#pragmapreprocessor directive can be used to directly insert an assembly directive or a line of assembly code directly into the generated assembly file. -
The
__LINE__and__FILE__preprocessor directives were implemented in this version. -
The arguments
int argcandchar **argvare now available as arguments to main. Up to eight arguments are supported. The argumentargv[0]points to the command string that invoked the program. -
The
stdlib,stdio,ctype, andstringare supported. -
The ElfC compiler now accepts inline comments (
// comments) as well as traditional C commments (/* comments */). -
The ElfC compiler now accepts
\eas an escape sequence for the ASCII escape character 0x1B. -
struct,unionandtypedefare now supported, except as function arguments and function return values. -
Pointers to
struct,unionandtypedefare now supported. A function may accept a pointer to astructorunionand a function may return a pointer to astructureorunion. -
&arrayis now valid syntax (you no longer have to write&array[0]). -
The
auto,register, andvolatilekeywords are recognized (as no-ops). -
enum's may now be local. -
externidentifiers may now be declared locally. -
Prototypes may have the
staticstorage class. -
The
#error,#line, and#pragmacommands have been added. -
The
atexit()mechanism is now supported. -
The
varargsmechanism is now supported as functions as described in the book Practical Compiler Construction by Nils M Holms. (Starting with version 3.3, the standard C mechanism forvarargsis supported.) -
The
assertmacro is implemented as a function with support for theNDEBUGmacro. (Starting with version 3.3, the standard C mechanism for theassertmacro is supported.) -
STG ROM break points are supported by the
_STGROM_andBRKPTmacros. -
A broader subset of C expression syntax is accepted in constant expression contexts. Pointer variables can be initialized with NULL.
More information about unsupported library functions and header files can be found on the ELFC Detailed Information page. Information about ElfC internals can be found on the ELFC Internal Information page.
Compiler Option Changes
-
Added the
-L(Library) ElfC option to compile and assemble a C source file into a prg file defining an Elf/OS (Mini/DOS) library procedure. -
The
-N(No libraries) option compiles without the stdio and stdlib C libraries. The user should supply the _init() function that is called by ElfC before the main function. -
Simplified the
-V(Verbose) option to display all verbose messages or none. There is no longer any need to specify multiple verbose options for additional messages.
More information about -L Library option can be found on the ELFC Detailed Information page.
Version 3
-
Version 3 adds support for the
signedandunsignedkeywords. -
This version implements a subroutine scheme for frequently used routines in the ElfC library to improve performance.
-
The generated code creates a string table for improved performance.
-
The stdlib defines the
size_ttype and the C library functions were updated to use this type. -
The unsigned conversion
%uis supported by the stdio printing and scanning functions. -
Several functions were replaced by inline assembly code to remove dependencies on BIOS functions.
-
The included files were cleaned up to eliminate unused definitions, and the kerneal api were moved to a separate included file.
More information about Version 3, signed and unsigned types and library functionscan be found on the ELFC Detailed Information page. Inf
Related Skills
node-connect
347.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
107.8kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
347.0kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
347.0kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
