chevron_left chevron_right
Login Register invert_colors photo_library


Stay updated and chat with others! - Join the Discord!
Thread Rating:
  • 0 Vote(s) - 0 Average


Tutorial Intro to CPU design [Part 3: CPU Level design] filter_list
Author
Message
Intro to CPU design [Part 3: CPU Level design] #1
If you have not done so already, please read part 2 of this series.

Alright, we are going to take a break from the math and work on our CPU system itself.

Some of these terms may not mean much to you, but part 4 will explain ALL of them. I have all of the drawings for part 4 already done, but I don't want to deal with any more math at 2 in the morning.



So, let's start with our low level aspects. Our CPU is a 4-bit, so we will need to be able to store these numbers somehow. We will use a databank made up of 4-bit registers. Since we can use only 16 different numbers, we will use 16 of those registers, totaling 8 bytes of total memory.
We will also use another one of those 8 byte databanks for our instruction storage, so we will have 8 bytes of user memory, and 8 bytes of program memory.

Next up, we need to decide how many general purpose registers we are going to use, and name them. I don't think we need any more than three, since we aren't doing anything too complex here. Let's use the following
A, B, and X for registers.

A and B are going to be our accumulator registers, and X will be our index register.

Now, we will need one more VERY important register: the instruction pointer (IP). The IP will keep track of what instruction we are executing. It will be updated every time a pipeline stage is completed.

So, we have A, B, X, and IP for registers. Yes, this is a VERY limited design, but it is intended to teach you how to make them, not make a perfect CPU you can use for gaming.



Alright, on to instruction set:
We will need a few instructions:
Code:
0 - LDA - load register A (with CONST)
1 - LDB - load register B (with CONST)
2 - MOVA - move register A (to REG)
3 - MOVX - move X (to REG)
4 - XORA - xor A (WITH REG)
5 - XORB - xor B (WITH REG)
6 - XORX - xor X (WITH REG)
7 - ADDA - A = A + (REG)
8 - STOA - store A to memory (AT ADDR)
9 - COM - 2's compliment (REG)
a - INV - inverse (REG)
b - LDMA - load register A (from ADDR)
There you have it, 11 different instructions. Each instruction takes EXACTLY one clock cycle. Each instruction takes up 1 byte (two nibbles).

Now, this can be quite confusing, so how about we make a simple program to do 1+1, and store that in memory at location 0x4:
Code:
LDA 1
LDB 1
ADDA B
STOA 4

but, we won't be able to program like that, we will need to do it in machine code, here is the same program (in hex)
Code:
01217184
Broken down:
01 ;LDA 1
21 ;LDB 1
71 ;ADDA B
84 ;STOA 4

There is something I didn't cover here: how do we encode register names?
Simple!
Code:
0 - A
1 - B
2 - X
3 - IP

Now, a sample program to do the following: 6 - 3 and store it in memory 15
Code:
LDA 6
LDB 3
COM B
ADDA B
STOA f

and in machine code:

06 ;LDA 6
13 ;LDB 3
91 ;COM B
71 ;ADDA B
8f ;STOA f

or

061391718f

It takes up 5 bytes of storage, which is 63% of our available memory, so programs will need to be short (you can use 8 lines of code total).



There you have it. Now, look forward to all of the documentation that goes along with these terms, as well as some of the functions actually used here.

[+] 1 user Likes phyrrus9's post
Reply






Users browsing this thread: 1 Guest(s)