I was once in a meeting where the facilitator asked us to introduce ourselves with the usual information, but also wanted us to share our favorite hobby. I spent a second trying to think of which hobby I could say to not sound like a total nerd. Then I realized it didn’t matter. All my hobbies are nerdy, including designing CPUs and their instruction sets.I actually started sketching out an instruction set when I was a kid, back when no one had home computers. I am glad I lost that notebook: it would be painful to see today. The first CPU I put on an FPGA wasn’t of my own design, though. I implemented BLUE from Caxton Foster’s Computer Architecture book. I also extended it and modernized it a lot. I really wanted a C compiler for it.C CompilationThat’s really the problem. C was once a simple language, but modern C is far from simple, and compilers are huge projects. I have looked before at porting GCC to a different architecture, and it looks daunting. There’s LLVM, which is a bit more modern, but also non-trivial to port. There are a few older compilers that ought to be easier, but they often aren’t quite modern enough. Plus, if your CPU were big enough, which BLUE isn’t, GCC or a similar modern compiler would be attractive because you could use it to get Linux going.Keep in mind, though, I’m not talking about a C compiler that runs on BLUE. Just a cross-compiler. My OneDer CPU is 32-bit and could host a C compiler, though. That’s another reason to bite the bullet and do a “big” compiler port. Because even if BLUE isn’t that big, other CPUs are, and I’d love to have a GCC port under my belt.DecisionsSo… what do I do? I have a few ideas for you to consider, and of course I’m open to other suggestions. One of the biggest problems with BLUE is that it is a word-oriented machine. Address 0, for example, is a 16-bit word. Address 1 is another 16-bit word that does not overlap.This is great until you get into strings: that is, character arrays. Should a character pointer be special? Or should you waste space by putting one character per word? The address space isn’t very large, so you could make character pointers that get converted at runtime, but there is a penalty for that, of course. Or, you could make everything a byte pointer and pay an even bigger penalty.Path 1: Port a Big CompilerObviously, the best result would be to port GCC or a similar compiler. It turns out, GCC has a PDP/11 port, and BLUE is not very dissimilar from a stripped-down low-end PDP/11. It seems like one idea would be to get the PDP/11 GCC source code and use it as a starting point.Of course, some compilers are made to be easier to port. SDCC handles CPUs with few registers, for example. Clang/LLVM and LCC are also compilers made to be easier to port.There is obvious appeal here. If I get GCC or LLVM producing good BLUE code, I’ve learned how to target one of the major compiler infrastructures. That knowledge might transfer to later CPUs and, in the case of a sufficiently capable future processor, could lead to things like Linux ports.The downside is obvious too: this may be solving a much larger problem than BLUE actually requires.Path 2: Port a Little CompilerThere are a few little compilers like pcc from AT&T, which was supposed to be portable. The Amsterdam Compiler Kit is old, but works. But these don’t have the modern features that GCC has.Another category of “little” compilers would be compilers that output some well-understood intermediate format. You could do this with LLVM, of course. Have it output IR code, then convert it without going back into the toolchain to do things like post-code generation optimization. QBE is another candidate that already has a C front end.Path 3: Use a Compiler with a VMThere have been a few compilers that generate code for virtual machines. A port for these only requires you to create what you hope is a simple VM and loader. An older commercial product, C-Flea, used this idea. There’s also subc and a few others. These often are not full-featured compilers, though.Path 4: Hijack and EmulateSince there is a PDP/11 port, one idea is to just emulate a PDP/11 with BLUE. The performance probably won’t be great, but it should be relatively quick. Definitely a hack and definitely not very satisfying. However, it is probably the easiest way to go, especially if you identify what instructions gcc programs use and drop emulation of things that the code won’t use.Path 5: Hijack and TranspileIf you want better performance, you could take PDP/11 assembly from GCC and transpile it to BLUE’s assembler. Again, this probably isn’t that hard, but it does seem unsatisfying. You wouldn’t need to convert the entire instruction set, just the things gcc emits.Path 6: Transpile FirstAs I said, early C was pretty simple. It should be possible to write something that mangles modern C into older constructs and then write or port a simpler compiler. This seems like the most unproductive work, but it is possible. You could then do something like port Small C or 8cc, which are pretty simple, and port them. You might even just write your own compiler.What Would You Do?Regardless of the path, the idea that BLUE is an FPGA-based CPU means that I can add instructions, if I need them, to make hosting C programs easier.So. You have a 16-bit accumulator-based CPU with a small amount of word-oriented memory. You have a working assembler with relocation support and a software emulator. You just need to decide how to create the C compiler. What would you do? Let us know in the comments.If you want to see an older version of BLUE in action, check out the very old video below.