Do you want to create a computer? All by yourself?
Do you want to do it step-by-step, starting with a single bit and ending with a design that can run real programs, written in C?
Do you also want to see how the design can be done using different languages, such as VHDL and Verilog?
Then this might be a book for you. The book will show you, in a step-by-step manner, how a simple computer can be created. While doing so, it will also provide an introduction to how computers work, and how their main parts can be constructed, and put together into a functioning design.
We start with a simple building block that can store one bit, and we end with a computer that can run software that is compiled and linked using gcc.
We choose to implement a subset of a real computer architecture - the OR1K architecture. In this way, we can convey the experience of building a real system, while at the same time - since we choose a suitable small subset - making the task small enough to be completed without a large implementation effort.
Using an already available architecture also allows us to use available tools, such as the OpenRISC GNU tool chain.
The book is designed as a Book with Views. This means that there are common parts, covering the general aspects of computer design, but also specific parts, treating view-specific material. We have chosen the views as languages. This gives us a possibility to treat the topic of computer design using different languages, but still keeping the material contained in one book.
The book has the following views.
The view you are reading now is Verilog. The purpose of this view is to show how Verilog can be used to construct a computer that implements a specific architecture.
We choose to describe our computer using a language. In this way, we can have a textual representation of the computer, and we can use the textual representation as input to software tools, that will help us to simulate the behavior of our computer.
Verilog is a hardware description language. We use Verilog to describe our computer, and to simulate its functionality. It is also possible to use Verilog to actually synthesize a computer, in real hardware, for example in an FPGA.
A simple example will get us started. We use a classical "Hello, world'' example, which will do nothing meaningful except printing a text string. The code for the example is shown in Figure 1. The code for the example is from the Icarus Verilog User Guide. We will start using Icarus Verilog in Section Getting some tools.
module main; initial begin $display("Hello, world"); $finish; end endmodule
Figure 1. A hello world example in Verilog.
The code in Figure 1 contains a module, which is named main.
We have chosen a language, to describe our computer. We have taken a first, tiny step, and we have seen how we can get hold of some tools.
Before we take our next steps towards building our computer, let's spend some time talking a bit of what we want to build.
Our goal is to create a computer. A computer reads instructions from a memory. Each instruction is represented as a sequence of bits. The values of the bits determine the type of instruction, and sometimes also arguments that the instruction shall use. The allowed instructions, for a given computer, belong to the computer's instruction set.
Most computers have instructions for loading data from a memory, and storing data to a memory. Other common instructions are instructions for doing mathematical operations, such as addition and subtraction, and instructions for making decisions. The decisions can be based on evaluations of certain conditions, such as checking if a number is zero, or if a certain bit is set in a piece of data.