Take the 2-minute tour ×
Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. It's 100% free, no registration required.

What a processor does with instructions and with data using examples. Why does it need data if it is processing an instruction?

share|improve this question

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, visit the help center. If this question can be reworded to fit the rules in the help center, please edit the question.

    
Nothing to do with electronic design! –  Leon Heller Nov 27 '12 at 8:52
    
You should show some research effort before asking a broad question like this. Have you tried looking in some textbook or on wiki? –  clabacchio Nov 27 '12 at 9:10

2 Answers 2

up vote 1 down vote accepted

Let's take an example of MOV Instruction. MOV A,#01 ; Move 01 in Acc

In this case, "MOV" is an Instruction and 01 is data for it.

MOV A,R0  ; Move contents of R0 in Acc

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".

share|improve this answer

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 ADD R1, R2, R3 What does this mean? Add the contents of register R2 to the contents of register R3 and store the resulting number in R1.

So in a slightly easier to read format:

ADD R1, R2, R3 is the same as R1 = R2 + R3

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:

ADDI R1, R0, 10 which is just R1 = R0 + 10 Since R0 is always 0, this will put the number "10" into the register R1.

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 ADDI R1, R0, 10 when assembled will become 0x2001000A which is binary: 001000 00000 00001 0000000000001010

To make that a bit more sensible, the first 6 bits are the opcode: so 001000 == 0x08 == ADDI

The next 5 bits are where we store the what register we're reading from: so 00000 == 0x00 == R0

The next 5 bits are where we'll store the answer: so 00001 == 0x01 == R1

And the last 16 bits are the "immediate data": 0000000000001010 == 0x0A == 10


Let's compare this with the other instruction we were looking at: ADD R1, R2, R3

When assembled, it will look like this: 0x00430820 which is binary 000000 00010 00011 00001 00000 100000

Just like before, the first 6 bits are the opcode: 000000 == 0x00 == ADD

And just like before, we will red from the register defined by the next 5 bits: 00010 == 0x02 == R2

And we will read the second chunk of information from the register defined by the next 5 bits: 00011 == 0x03 == R3

And we will store it in the register defined by the next 5 bits: 00001 == 0x01 == R1

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 0x2001000A which is exactly 32 bits, same as the ADD.

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 lw R1, 0x37 This will go to address 0x37 in memory, get the value stored there, and put it in R1. This data can then be used in ADD instructions, just like you would with the immediate.

I hope that explanation is helpful because I spent way too long writing it!

share|improve this answer
    
Thanks alot for explanining with patience and for time :) –  deepu Nov 27 '12 at 11:48

Not the answer you're looking for? Browse other questions tagged or ask your own question.