Sunday, September 5, 2010

In which I attempt to design a CPU, part 1

The CPU is a chip at the core of your computer. It does all the "work" that lets you do useful stuff: all the math, all the logical processing, to create an environment in which you can work. It receives your input. It sends your output to a graphics chip for processing, or if none is available, makes the picture itself. It does all your calculations. And it's very very complicated.
So if I'm going to make one, first I'll need an instruction set, that controls what it can do. First I have to decide what it needs to do: Math, logic, control, and manipulation. Also, a little bit of storage, so the calculations we do last until we can put them in memory.

* Math
- Addition
- Subtraction
- Multiplication
- Division
- Modulo (Divide, throw away the result, and provide the remainder.)

* Control
- Unconditional jump ("Goto")
- Branch if ("If X then Y")
- Store (in memory)
- Load (from memory)
- Interrupts (little microcode programs that do everything from print to quit)
- Rotate left (Shift every bit left by one, carry over the leftmost to a flag, and the flag to the rightmost. Encryption uses this.)
- Rotate Right (Like rotate left, but in the opposite direction)
* Logic
- AND (Both conditions required)
- OR (Either condition required)
- NOT (Switch to the other)
- XOR (One, or the other, but not both)
- Compare (Is X the same as Y?)

* Redundant (things that are covered by the above, but I want a special code for because the special code can do whatever FASTER.)
- Increment (Add 1)
- Decrement (Subtract 1)
- Shift left (Effectively, multiply this by 2)
- Shift Right (effectively, divide this by 2)

Each of these will need to be assigned a number, which tells the CPU to use that operation. And then either we'll have to have circuits that perform that action fabricated, or microcode to perform that operation written. Most CPUs these days use microcode, because it's faster and cheaper. I think, though, that I'd rather implement with hardwired logic, on the grounds that a more power-efficient design can be made that way. Besides, this is supposed to be simple.
Now arguably, multiplication and division are redundant operations too, because multiplication can be implemented as a loop of additions, and divison as a loop of subtractions, but they're so common in computer operations that I think they do deserve their own opcode. Besides, I do expect to be able to do floating point stuff.

No comments:

Related Posts Plugin for WordPress, Blogger...