SkillAgentSearch skills...

ELFC

A C compiler for a CDP1802 microcomputer running Elf/OS or Mini/DOS

Install / Use

/learn @fourstix/ELFC
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

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.c into the directory.
  • Use the command elfc hello.c to compile the hello.c to hello.elfos
  • Transfer the hello.elfos file 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 #pragma statements 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 asm statement passes a string literal directly into the generated assembly file.

  • The #pragma preprocessor 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 argc and char **argv are now available as arguments to main. Up to eight arguments are supported. The argument argv[0] points to the command string that invoked the program.

  • The stdlib, stdio, ctype, and string are supported.

  • The ElfC compiler now accepts inline comments (// comments) as well as traditional C commments (/* comments */).

  • The ElfC compiler now accepts \e as an escape sequence for the ASCII escape character 0x1B.

  • struct, union and typedef are now supported, except as function arguments and function return values.

  • Pointers to struct, union and typedef are now supported. A function may accept a pointer to a struct or union and a function may return a pointer to a structure or union.

  • &array is now valid syntax (you no longer have to write &array[0]).

  • The auto, register, and volatile keywords are recognized (as no-ops).

  • enum's may now be local.

  • extern identifiers may now be declared locally.

  • Prototypes may have the static storage class.

  • The #error, #line, and #pragma commands have been added.

  • The atexit() mechanism is now supported.

  • The varargs mechanism 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 for varargs is supported.)

  • The assert macro is implemented as a function with support for the NDEBUG macro. (Starting with version 3.3, the standard C mechanism for the assert macro is supported.)

  • STG ROM break points are supported by the _STGROM_ and BRKPT macros.

  • 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 signed and unsigned keywords.

  • 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_t type and the C library functions were updated to use this type.

  • The unsigned conversion %u is 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

View on GitHub
GitHub Stars8
CategoryDevelopment
Updated1d ago
Forks2

Languages

C

Security Score

85/100

Audited on Apr 2, 2026

No findings