What a processor does with instructions and with data using examples. Why does it need data if it is processing an instruction?
|
closed as not a real question by Leon Heller, clabacchio♦ Nov 27 '12 at 9:07
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, see the FAQ.
Let's take an example of MOV Instruction.
In this case, "MOV" is an Instruction and 01 is data for it.
Here we "Data" is content of R0. To Summerize, Processor executes instructions and for that it requires certain Data. In C, You pass paramters to functions. It can be treated as "Data" required to process "Instructions". |
|||
|
Quick note before I start answering this question, I'm going to be using a mips-like assembly language. In this language, R0 (or register 0) always has the value 0 in it, even if you try and store a different value in R0. For the sake of simplicity, all the other registers behave as you would expect them. So essentially the idea is that you have an instruction which does something. Let's say, for example, you have So in a slightly easier to read format:
Makes sense? Good! So what is in R1? Most of the time, you will do something to put a value or "data" into that register. For example:
Still following? So the number 10 in this case is called "immediate data". To see why requires a bit more explanation about how the instruction looks to the CPU. So To make that a bit more sensible, the first 6 bits are the opcode: so The next 5 bits are where we store the what register we're reading from: so The next 5 bits are where we'll store the answer: so And the last 16 bits are the "immediate data": Let's compare this with the other instruction we were looking at: When assembled, it will look like this: Just like before, the first 6 bits are the opcode: And just like before, we will red from the register defined by the next 5 bits: And we will read the second chunk of information from the register defined by the next 5 bits: And we will store it in the register defined by the next 5 bits: The remaining bits contain information which doesn't matter in this example! So when the processor gets an instruction in mips, it will always grab 32 bits at a time. The ADDI came out as So the processor will take the information in those 32 bits, and use them as the instruction it executes. So, without doing any more work aside from fetching the 32bits of instruction, the "10" in our ADDI instruction is available to the processor. Since the processor doesn't have to do any more work, it is "immediately" available, and hence the name "immediate data". But let's say we had a value stored in memory because say... a user typed in 346 using the keyboard. Clearly, that can't already be in the code as "immediate data", we have to get that data from somewhere else. So for these situations (and obviously many others) we have instructions which fetch data. Take the code I hope that explanation is helpful because I spent way too long writing it! |
|||
|