How does a processor 'know' what the different commands mean?
I'm thinking of assembly level commands like MOV, PUSH, CALL, etc...
Answer
When a computer interprets assembly level instructions, these instructions are turned into their binary equivalents for the CPU to read. When the CPU executes the instructions, it interprets the opcode part of the instruction into individual "microprograms", containing their microcode equivalents. Just so you know, a full assembly instruction consists of an opcode and any applicable data that goes with it, if required (e.g. register names, memory addresses).
Microcode instructions are extremely low-level (more so then assembly), and control the actual digital signals which control the flow of logic in the microprocessor. For example, one microcode instruction could update a condition code register flag with a new value, or connect a CPU register with one of the ALU units. More complex tasks are possible, but this shows you the general idea of what microcode is used for.
The general flow from compilation to execution is as follows. The assembly instructions are assembled (turned into their binary equivalent 0s and 1s, or from now on, logic signals). These logic signals are in-turn interpreted by the CPU, and turned into more low-level logic signals which direct the flow of the CPU to execute the particular instruction. This can take one or more clock cycles, depending on the processor's architecture and design (most processor reference manuals tell you how many clock cycles it takes to execute a particular instruction, like this one for example).
All of this is done with hard-programmed microcode (physically embedded within the processor in some kind of ROM, set during manufacturing), which directs the flow through actual low-level logic gates. This provides an interface between the abstract assembly instructions and the physical electrical logic in the processor.
So, in summary, processor instructions are assembled and loaded by the processor. The processor will then use these instructions to look up the microprogram (in the form of microcode) corresponding to that particular instruction, which is what "actually" executes the instruction. Once the microcodes for the particular instruction have been executed (which can take one or more clock cycles), the processor executes the microcode to fetch the next instruction, and the cycle repeats.
No comments:
Post a Comment