Ask HN: did you ever implement a toy processor?

6 points by amenghra ↗ HN
Did you ever implement a toy processor? Was it from scratch or were you given pieces to complete? Do you think it was worth the effort and did it help you become a better coder?

I'm asking this because I feel there isn't any easy way to write/debug and run fpga projects. I would like to change this, and I'm wondering if others feel the same?

9 comments

[ 3.3 ms ] story [ 31.5 ms ] thread
(comment deleted)
Thanks for your response.

Did you like the tools you used to test your vhdl? Did you run the code on a fpga and did you find it easy to do?

Do you wish you could demo your processor to anyone using a javascript simulator?

(comment deleted)
I made a processor <edit> I emulated it </edit> in c++ in college. Started off with an abstract logic gate that had two inputs and an output, created an event queue to propagate outputs to inputs, created a couple of different buses, tristate and open drain I believe, and then created methods to link inputs and outputs as well some concrete logic gate classes to each other and also to the various bus end points.

The event queue even handled propagation delay.

I made it so that if a tristate bus was held to both high and low at the same time, then an exception would be thrown that told you you "let the blue smoke out" and ended the program.

Binary instructions were read from a static string buffer which were then interpreted by the logic to implement the functions of the cpu and alu.

In the end, I discovered that the cpu logic block that we had been told to emulate was missing a one clock cycle delay buffer and should not have functioned properly if anyone else implemented it accurately.

Wish I still had the code for that, it was super fun to make.

This sounds like a really great way to get started without having to invest (time, money or both) in unfamiliar tools.
I architected an application-specific custom processor with about 25 instructions and implemented about 20% of it on an FPGA (the rest 80% was implemented by other team members). I also created software tools for this.

While this was not a toy processor per say (it was a part of a bigger project), I consider it toy-like because of the simple instruction set. Writing and debugging was not a major pain point in this case. Generally speaking though, I have been fairly satisfied with logic design tools for ASICs, though not as much for FPGAs.

I later discovered CAD tools built specifically for designing processors. Google ASIP [1] for more if interested.

Regarding this making me a better coder, well no, since I was already a good coder. :-) OK, I learned machine code at the age of 15 years, and so already had good insights into how stuff works inside when I learned C and C++.

[1] http://en.wikipedia.org/wiki/Application-specific_instructio...

I've implemented processors with narrow functionality using Am29116 and Am2901 devices. They we're simple but not toys, per se. The software infrastructure to recreate this mostly doesn't exist, unfortunately, and the comparable FPGA equivalents are vastly more capable. It was, however, an amazing learning experience.
TKGate (http://www.tkgate.org/) is an awesome visual tool for discrete logic simulation, and comes with a toy processor as an example circuit. I implemented a simple 32-bit MIPS-like processor in TKGate as well as the DLX architecture from Hennessey and Patterson. I also designed and implemented my own microcoded 8-bit processor for variety. That project eventually included bootstrapped assemblers and disassemblers, and an emulator in C for faster simulations. Here's some of my TKGate work: http://xidus.xidus.net/mips

Check out TECS/NAND2Tetris to get started with VHDL and processor architecture: http://www.nand2tetris.org/ If you want a more academic approach, try Hennessey and Patterson's Computer Architecture: A Quantitative Approach.