Build a Fun CPU in Your Browser

A rite of passage for a digital designer is to build a CPU. That may seem a formidable task and if you are thinking of building a modern CPU like the one in your PC, it is. However, a simple CPU is well within the reach of anyone who can sling some logic gates or HDL. We’ve even seen CPUs built in Minecraft. Now you can play nandgame and build a CPU step-by-step in your browser.

The game is based on the popular From NAND to Tetris site. True to the name you start out with a single NAND gate as a tool. From there you build an inverter, an AND gate, adders, flip flops, registers, and the like. You get a little help from the accompanying text and there are some blacked out hints if you get stuck.

The site notes that it is not complete yet, and we presume it means there should be more explanatory text. By the time you are building the ALU and instruction units, the text is a little sparse. However, it is a great way to experiment with how a CPU works internally and it is sort of fun, too.

We only had one real complaint. There are a few things that are made unnecessarily difficult because there is no way to get a solid logic 1 or 0 into the design — something that would not be true in real life. In addition, the feedback loops used to build flip flops isn’t very practical either, but at least it doesn’t make the game more difficult than real life. But it would be nice if they noted that in real life you’d have trouble doing as they suggest.

A lot of the custom CPUs we’ve seen on FPGAs are just toys. But two come to mind that are not. [Robert Baruch] has a custom CPU that can play Zork. We were very impressed with [F4HDK’s] A2Z computer which not only sports a powerful custom CPU, but also has an OS, a file system, and a set of utilities.

14 thoughts on “Build a Fun CPU in Your Browser

  1. tried it, fun. but it’s more like a puzzle than designing a cpu, the exercises are too “guided” to actually design a cpu. you have to build specific blocks and at the end just assemble them. I found that upgrading a given design to add, as example, new instruction, or try to reduce the cycle count for given instructions is way more interesting an rewarding. nice puzzle through

    1. Yes you have to meet their design spec and there’s often only one real way to do it, although there is some latitude. I had thought the same thing though. It would be cool to have a palette of all the modules you built and let you build whatever you wanted with it.

  2. I wonder why they skip the humble Nor gate…

    Though, their method of incrementing a variable is pure stupidity if one were to use it in a real design…
    There are though far less circuit intensive methods of doing it if one wants to not use the full adder and a simple constant.
    But for most systems that doesn’t do out of order execution, or work on multiple instructions in parallel, then using the full adder and adding a 1 to the start is fairly basic and will save one a lot of transistors. Having a dedicated instruction to increment or decrease a variable is nice, but there is very rarely a need for making dedicated hardware for it. (Other then a little glue logic to decode the instruction.)

    It is a neat little game, but I wouldn’t recommend it as a learning tool.

    1. I mentioned I didn’t like the way they handled that either. However, I could see doing this with a little lecture help with students for the first day of a unit where I would have them build their own real CPU. It kind of takes the edge off of it, I think, even though I agree I wouldn’t have made some of the design choices myself.

      1. I have never understood why nand gates gets all the glory….
        Nor and Xnor can also do it.
        Xor gates can do it as well. (in practice, on paper one needs at least a source for a logic high to be able to do it)
        And even the humble Not gate can technically do it in practice as well, if it only has a pull up or pull down capable output. (Here some people might notice how our interconnections now becomes AND or OR gates depending on the not gates around the wire.)

        And if someone feels like commenting that “that doesn’t work.” then go and try. (The humble diode is a nice way of making the standard hex inverter only capable of pulling its output to one state, in case one doesn’t have a “fancy” not gate in one’s drawers. Otherwise a handful of transistors and a bunch of resistors does wonders.)

  3. I admire the skill of producing this, and the goal of teaching people how to do logic design.

    But we stopped doing digital logic with gates and schematics back in the 90’s. Get them started using an HDL. Even a simple pidgin language would be better than messing around with all that manual wiring.

    1. do people design actual chips using HDL? Or do they design it with gates and schematics?

      I always thought HDL was only for FPGA. To make a functional hardware tool with generic hardware. Or using it as a proof of concept using FPGA before going into high cost production/deisgn of a real chip.

      1. Back in the 80’s, I did VLSI chip design by pushing rectangles of silicon, oxide and metal around. I doubt that’s done much anymore, except possibly for specialized leaf cells or analog designs. Now its mostly HDL and the software translates it to a physical structure. [Here]( is a high-level view of chip design from a few years ago.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.