A Small-C cross-compiler for the IBM 1401
The IBM 1401 was the world's most popular computer for the largest part of 1960s. It was introduced by IBM in late 1959 and was sold or rented until the early 1970s. Compared to today’s standardized world, the 1401 had a unique architecture. It was a binary-coded decimal, variable word length computer with up to 16,000 characters of core memory. It was the first to have a transistorized CPU. It had dedicated connections to a console typewriter, a high-speed line printer, a card reader-punch, up to six tape units, and even an hard disk system. The Computer History Museum in Mountain View, CA has two fully operating 1401 systems, each with a full set of peripherals except the hard disk and the typewriter.
So why are we writing a C compiler for a computer that predates that language by 13 years? The first answer is, indeed, because there isn’t one. The second answer is because it’s fun! I’m a senior computer science student at San Jose State University. When I choose the final project for my Compiler Design class, I wanted to do something that, no matter how difficult, could be used not just in class. I was already familiar with the 1401s at the museum, and I was aware of the efforts of the volunteers there who wrote demo programs in Autocoder assembly language. They use ROPE, written in Java by Ronald Mak, the instructor of the Compiler Design class at SJSU. ROPE wraps a simple but good GUI-based IDE around an Autocoder assembler written in Fortran by Van Snyder and the SIMH 1401 simulator written in C by Bob Supnik. After debugging a program with ROPE on a PC or Mac, the volunteers can then run the program on the actual 1401 hardware. The machine language of the 1401 was quite primitive compared to today’s machines and had no stack and subroutine instructions. Powerful macros helped a lot but programming remained cumbersome compared to programming a more modern machine in C.
To make the challenge feasible, my classmates, Sean Papay and Matt Pleva, and I developed a cross-compiler written in Java using JavaCC to generate the parser and scanner. Java also gave us the advantage to develop the compiler and run it on any modern architecture and, in a following step, to integrate more easily with ROPE. We decided to implement Small-C, a subset of C for very small and embedded systems, originally developed for the Intel 8080 by Ron Cain in 1980. We implemented some additional features Small-C doesn't have but are common in more recent versions of C, such as structures and constants. Our compiler translates programs written in Small C into working Autocoder programs that can run on the actual 1401.
We completed a first working “beta version” of the compiler by the end of the spring 2015 semester. Matt and I are continuing the project during this summer semester to complete an optimized release with all our planned features. The current version of the compiler works correctly but needs to be optimized by emitting fewer stack macros that are memory consuming and slow. Time permitting, we will try to generate code that takes advantage of the 1401’s variable-word-length feature. We expect to complete it by the end of this summer.
Comments are welcome