In computer hardware engineering, how does the electricity and the little bits of silicon work, what’s the “lowest level” of computer engineering and how does that work, and how does that scale and translate up into writing software? i.e. hardware -> machine code -> assembly -> higher level programming languages?
I think mostly I’m just curious about the bridge between software and hardware, and how to get there, but I have no idea where to start.
In: 1
The state of a processor at any given moment contains a couple of small pieces of data stored in *registers* (a tiny bit of memory hard-wired into the processor). A couple of those pieces are actual data loaded by previous instructions, along with its current *opcode* (the next operation the processor will perform) and a pointer that tells the processor where to look for the next opcode.
The processor has a bunch of circuits. Those circuits contain logic gates, and perform operations. Which circuit is active is controlled by the current opcode, so you can effectively think of a processor as a bunch of one-task circuits switched on and off by the opcode.
For example, the processor might contain [opcode 001] [register 1 010101010111] [register 2 1111111111] [next instruction at 110101000110101]. If opcode 001 corresponds to a circuit that says “add registers 1 and 2, then store the result in register 2 [and then load the next step of computation, as in any opcode]”, then the state after this instruction would contain whatever the opcode at the next-instruction location is, an identical register 1, the sum in register 2 (with some overflow, in this case), and the next-next instruction at the next-instruction step. The processor has other circuits, but the opcode stops them from being active.
[I am leaving out a few things here. In particular, most processors are a bit “smarter” than this about how they execute instructions, and a processor in most practical settings is also wired to other things that add extra registers with information coming in from outside.]
A sequence of opcodes is called *machine code*.
Assembly language is basically just a human readable version of machine code, with a little extra stuff. A small program, called an *assembler*, written directly in machine code, translates assembly language into machine code.
Then, yes, higher languages are built on top of assembly, and then other languages can be built on top of those, and so on. The key idea is that each higher language basically feeds some string (possibly human-readable text, possibly some other numerical codes) into a program written on a lower-level step, and that program has instructions that say “if fed in X, output Y lower-level code”.
Latest Answers