Skip to content
C Compiler hacking - starting with Small-C by Ron Cain
C Other
  1. C 99.1%
  2. Other 0.9%
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
.st.s.swp
LICENSE
Makefile
README.md
array1_test.pl
array2_test.pl
bug1_test.pl
bug2_test.pl
c5libp.c
c80.c
c85.c
c86.c
cc500.c
comp.c
condition1_test.pl
d.ws
gcd.pl
if1_test.pl
local_test.pl
ncc.c
pcc.pl
plo
plo.c
s.c
smc386c.c
st.c
t.c
t.pl
t.py
test.c
test.pl
test1.pl
test2.pl
while1_test.pl

README.md

scc

C Compiler hacking - starting with Small-C by Ron Cain

First I used the version from here:

http://www.physics.rutgers.edu/~vitchev/smallc-i386.html

Evguenily Vitchev add for and do statements while outputing 32bit GAS assembler suitable for the GNU toolchain. This lets you compile 32 bit programs.

From EV website:

Build a stage 1 compiler:
gcc -o smc386c1 smc386c.c
Using the stage 1 compiler build a stage 2 compiler:
./smc386c1
Output filename? smc386c2.s
Input filename? smc386c.c
Input filename? <enter>
There were 0 errors in compilation.

You must add -m32 so gcc compiles for 32bit
gcc -m32 -o smc386c2 smc386c2.s
In order to make sure everything went properly, go to stage 3:
./smc386c2
Output filename? smc386c3.s
Input filename? smc386c.c
Input filename? <enter>

diff smc386c2.s smc386c3.s
If diff doesn't produce output, this means the bootstrap was successful, and you can use the stage 2 compiler smc386c2.

This is the first copy of Small-C that I found that ouputs a usable ASM file for modern Linux systems. Of note however that the original Small-C I could find, did compile successfully, I just had to rename inline function to inline2 as inline is used by gcc. It output asm for the 8080 which of course you cannot use without an emulator but it's pretty amazing that something 30 years old compiled that easily.

You can’t perform that action at this time.