Yogi rides the new 6 wheeled robotic base platform. Designed in Solidworks and milled on my CNC machine.

Friday July 20 , 2018
Font Size

Your First CPU - Chapter 1 - Basic CPU


Article Index
Your First CPU - Chapter 1 - Basic CPU
Principles of CPU Design
YFCPU Source Code
All Pages

In this first chapter we learn the very basics of a CPU's core logic. We include basic Function Unit logic such as logical operators and math functions. To keep our first chapter simple, branching is not yet implemented so our programs are strictly linear and cannot include loop constructs. Also, the program code is included directly in the CPU source file.

Author's Goals

I hope that you will follow along with me and create your own version of yfcpu. If you simply copy my code you will not truly learn what I am trying to teach in these articles. As I write this now, I have a theoretical understanding of CPU design. I hope to put into practice the theory I know and deepen my understanding of the subject. Thus I don't claim to be an expert in this field but my goal in the final chapters is to develop an efficient embeddable CPU with pipelining and data/instruction caches. I also hope to compile and run ucLinux with it inside an FPGA. I hope my learning process as I write these articles will help as I am not so far removed in experience as possibly the reader. I may return to earlier chapters and write footnotes or sidebars if new knowledge deems it appropriate.

If you are familiar with FPGAs, HDLs and basic CPU design, you can skip to page 3 for the YFCPU Verilog source code.

Why a custom CPU?

A custom CPU implementation allows you to customize the instruction set for your application specific operations. This would only be beneficial for embedded type applications. If you are creating a small mp3 player for market your custom CPU could contain instructions for fast audio decoding thus requiring a lower overall clock speed and thus less expensive chip production technology. Furthermore, the removal of unnecessary instructions will reduce the logic footprint and possibly decrease the overall logic delay and thus increase your allowable instruction cycle time. Finally, in our case we wish to learn how processors work internally and how better to accomplish this than making our own simple RISC based processor.

Hardware Description Languages (HDLs)

Hardware Description Languages is what we currently use to design the behavior of logic circuits. In the older days of Commodore 64's, early Intel's and other processors, processors were designed by hand, laying out the layers of an IC's substrate masks using regular drafting techniques. Seymour Cray of Cray computes used #3 pencils! There were little or no computer aided design tools to help the chip developer. This method was tedious to say the least and few people had the patience and skills for such a task.

Thankfully, times have changed and designing custom processors is within reach of many hobby designers. Especially, if we already have computer programming experience, the switch is a simple paradigm change in thinking given the nature of software programs versus logic circuits. Generally, computers programs are executed serially and hardware descriptions are primarily parallel and near instantaneous, (disregarding sequential circuits for the moment).

HDLs give us a way to describe and implement a hardware design in a similar manner as developing a software program. We also have similar tools like compilers, debuggers and simulators.There are two predominate HDL language, Verilog and VHDL. We will use Verilog because it has a simpler syntax, some of which is similar to the C language.


There are two mainstream technologies for implementing a real IC based on your hardware description, FPGA and ASIC. You get an Aplication Specific Integrated Circuit part by sending your hardware description and a lot of money to a IC manufacturer. ASIC is a more recent term for "making your own IC". An Field Programmable Gate Array is a much cheaper alternative for small quantities. An FPGA contains a bucket of unconnected logic gates and allows us to program the connectedness of these logic gates using the FPGAs built in routing gridwork. Most FPGAs also allows us to reprogram them many times or even "in the field" allowing our application to have the latest functionality and bug patches.

What are IP cores?

You may have already found opencores.org. This is a great site with many freely available CPU cores and other IP cores. An IP core is simply a specific implimentation of a logic unit, whether it be a CPU or peripheral or other logic device. The IP stands for intellectual property. From opencores.org you can download one or more of these IP cores and instantiate them inside an FPGA device creating your own application specific System-on-Chip (SoC). Some companies specialize in creating and selling IP cores for various tasks, and in one such case I found a company that created a hardware based Java processor. They did not sell real ICs, only the descriptive logic source code for implentation inside an FPGA or ASIC.

User Rating: / 64

RSS Feeds

Visitor Poll

What sort of peripherals do you desire in a robotics main board? (you may vote more than once.)

Who's Online

We have 57 guests online