So the lowest level we can "program" is individual instructions on a processor, but those instructions had to be programmed somehow in the first place. How does a processor know what to do when an instruction is run?
views:
104answers:
4It's called "microcode" (or at least that's how it was called when I last looked at those 15+years ago).
The different hardware functional engines in the processor are coordinated with "microcode" software: fetch, decode a "machine code", execute etc.
Useful articles:
http://www.gamezero.com/team-0/articles/math_magic/micro/ How to design a simple processor...
The lecture notes to this course: http://www.stanford.edu/class/ee382/ Processor Design
Thinking in simplistic terms as the older processors would do it:
If you look at the instruction bits for most processors you will start to see patterns. A few bits define one of the input registers, a few bits might define another input register, a few bits might define the result register, and a few bits define the operation. So some parts of the hardware look at the bits that define operand a and they use that to connect operand a to the alu, other hardware uses the operand b bits to route operand b to the b input on the alu. Other bits select the operation that the alu is supposed to do, add, and, or xor, etc. Lastly the results bits route the output of the alu to the register that is to hold the result. A bit simplistic but at the same time is not that far removed from how logic is written and how traditional processors and many of the smaller ones operate. This is quite literally how the earliest computers operated, and "programming" them involved routing the answer from this alu into an input on that alu along with an input from the other thing until the result came out the end that you were looking for.
Some of the bigger modern processors are microcoded meaning there is actually another layer of instructions inside, your c = a + b operation may turn into a series of microcoded instructions that are kick started when your machine instruction comes in, and these would help perform the route the inputs to adder logic and the result back to the output types of things.
Logic these days is implemented using programming languages like verilog and vhdl, which are pretty close to existing software programming languages. The difference being that many of the lines in the "code" execute at the same time, not necessarily in sequential order as you would with normal software. Given some well written hdl it is not hard to pick up the language and understand what is going on. You might want to check out opencores.org and grab the source for one of the many processor clones. The compiler tools for hdl is not far removed from that used for software, instead of instructions the code is boiled down into logic or gates, this bit anded with that bit, this bit ored with that bit. Modules that can be implemented easily in logic and wired together. And just like you can take a C program and run it on many processors and operating systems, you can take hdl and compile it for the types of gates in different fpgas or logic modules for different foundries.