Intro to CPU design [Part 1: binary and numerical systems] 12-21-2014, 08:29 PM
#1

Preface

Okay, so why don't we make a series of tutorials on CPU design. I will make them complete with drawings, all of the maps, and part numbers. By the end of this series you will have a fully programmable CPU to play around with and hopefully a better understanding of how they work.

For the purpose of simplicity, I will be using a RISC-like architecture. I won't go in-depth on the pipeline used here, just know that there is a very crude implementation of one going on.

Binary and numerical systems

A binary (or base-2) numerical system is a system in which only two values are used:

HIGH - binary 1

LOW - binary 0

This is what we will use at the base level of our CPU. In CPU design we use electron states to determine logic values. We will only use 2 (of the many) electron states, since they are easy to produce. Currently no CPU on the market uses any more than two electron states, quantum computing is still in its early stages.

Counting in binary

It is actually quite simple. Since we will be using a 4-bit CPU, we will include all 4 bits in our counting. 4 different bits means that we will have 16 different values (v(n) = 2^n), so let's count to 16:

now, why didn't we make it to 16? Simple. We have 16 possible values, that INCLUDES the 0. The maximum count for each set of bits is m(n) = v(n) - 1

therefore m(4) = v(4) - 1

or

m(4) = (2^4) - 1

or

m(4) = 16 - 1 = 15

Now, I assume you have counting in binary down, we need to work on addition and subtraction.

lets do 7+6 in binary. It helps if you have that table of binary to decimal memorized, we will go into conversion in a minute.

7 = 0111

6 = 0110

ALWAYS go from right to left. remember the rules:

0+0 = 0

0+1 = 1

1+0 = 1

1+1 = 10

Now, let's check that, 1101 in binary is 13. 6+7 in decimal (base 10) is 13. SUCCESS!

Subtraction follows the same rules. I really don't need to teach you that one do I?

The only difference in subtraction is:

0000 - 0001 = 1111

When we have to borrow, and we run out of bits to borrow from, we just assume the next bit to the left (bit 5 in this case) is a 1.

numerical systems: hexadecimal

Hexadecimal is basically just a notation system for our binary, it makes it easier to write it all out. Hexadecimal (or hex) is a base-16 system, so for every 4 bits of binary we will have exactly one digit. Just memorize this table for conversion:

So, our 0111 + 0110 example, in hex can be written 7 + 6.

For compadibility, we will no longer be using decimal in ANY part of this tutorial. Every number from here out will be either written in binary or hex.

Adding or subtracting hex numbers is best done by converting to binary and using the method I described above, and then using the table to convert it back to hex. If you know the real method, use it.

Next up: binary logic! This is where stuff gets freaky. Boolean algebra and stuff. Let me know what you think/rate this thread/rep.

Okay, so why don't we make a series of tutorials on CPU design. I will make them complete with drawings, all of the maps, and part numbers. By the end of this series you will have a fully programmable CPU to play around with and hopefully a better understanding of how they work.

For the purpose of simplicity, I will be using a RISC-like architecture. I won't go in-depth on the pipeline used here, just know that there is a very crude implementation of one going on.

Binary and numerical systems

A binary (or base-2) numerical system is a system in which only two values are used:

HIGH - binary 1

LOW - binary 0

This is what we will use at the base level of our CPU. In CPU design we use electron states to determine logic values. We will only use 2 (of the many) electron states, since they are easy to produce. Currently no CPU on the market uses any more than two electron states, quantum computing is still in its early stages.

Counting in binary

It is actually quite simple. Since we will be using a 4-bit CPU, we will include all 4 bits in our counting. 4 different bits means that we will have 16 different values (v(n) = 2^n), so let's count to 16:

Code:

`0000 = 0`

0001 = 1 ;now we do something funky, we have to do a carry, resulting in this:

0010 = 2 ;1 + 1 = 10, remember that, it is important!

0011 = 3

0100 = 4; 11 + 1 = 100, because 1 + 1 = 10, then we have 1 + 1 again.

0101 = 5

0110 = 6

0111 = 7

1000 = 8

1001 = 9

1010 = 10

1011 = 11

1100 = 12

1101 = 13

1110 = 14

1111 = 15

therefore m(4) = v(4) - 1

or

m(4) = (2^4) - 1

or

m(4) = 16 - 1 = 15

Now, I assume you have counting in binary down, we need to work on addition and subtraction.

lets do 7+6 in binary. It helps if you have that table of binary to decimal memorized, we will go into conversion in a minute.

7 = 0111

6 = 0110

Code:

`0111`

0110

------

0+0 = 0

0+1 = 1

1+0 = 1

1+1 = 10

Code:

`0111`

0110

------

xxx1 (0+1 = 1)

0100 (carry the 1)

0111

0110

------

xx01 (1 + 1 = 10)

1100 (carry the 1 again)

0111

0110

------

x101 (1 + 1 = 10, 0 + 1 = 1)

1100

0111

0110

------

1101 (0 + 0 = 0, 1 + 0 = 1)

Final answer: 1101

Subtraction follows the same rules. I really don't need to teach you that one do I?

The only difference in subtraction is:

0000 - 0001 = 1111

When we have to borrow, and we run out of bits to borrow from, we just assume the next bit to the left (bit 5 in this case) is a 1.

numerical systems: hexadecimal

Hexadecimal is basically just a notation system for our binary, it makes it easier to write it all out. Hexadecimal (or hex) is a base-16 system, so for every 4 bits of binary we will have exactly one digit. Just memorize this table for conversion:

Code:

`binary hex decimal`

0000 = 0 = 0

0001 = 1 = 1

0010 = 2 = 2

0011 = 3 = 3

0100 = 4 = 4

0101 = 5 = 5

0110 = 6 = 6

0111 = 7 = 7

1000 = 8 = 8

1001 = 9 = 9

1010 = a = 10

1011 = b = 11

1100 = c = 12

1101 = d = 13

1110 = e = 14

1111 = f = 15

So, our 0111 + 0110 example, in hex can be written 7 + 6.

For compadibility, we will no longer be using decimal in ANY part of this tutorial. Every number from here out will be either written in binary or hex.

Adding or subtracting hex numbers is best done by converting to binary and using the method I described above, and then using the table to convert it back to hex. If you know the real method, use it.

Next up: binary logic! This is where stuff gets freaky. Boolean algebra and stuff. Let me know what you think/rate this thread/rep.