Every thing is a number for a micro controller. How does it then treat data, address, and an instruction separately ? Here is the answer….
Here I write mainly about 8 bit micro controllers. The same principles hold good for 16 bit and 32 bit controllers/processors. An 8 bit micro controller means, it can process 8 bit data at a time. 8 bit data can be stored in a register made of 8 flip-flops in a row. Each flip-flop can take only one value (0 or 1) at a time.
We have already seen that a micro controller can understand only binary numbers. They are stored in flip-flop arrays. Thousands of such arrays in different forms are used. If these arrays are implemented using non-volatile memory technology like flash, they become part of programme memory. So every thing we store in programme memory is a binary number. Volatile memory also stores binary numbers.
Instructions are also binary numbers. They are stored in programme memory. Any controller operation has to go through an FDE cycle.
Fetch the instruction (a binary number) from the programme memory location.
Decode that instruction and find its meaning. This is a very complicated process and is done in the control unit section of the cpu. To simplify, we can say that a programmable logical array is used to find its meaning. Suppose the instruction is an “add” instruction. The binary number corresponding to “add” is fetched from the programme memory and another number corresponding to that number is found out.
Execute the “add” operation. The new binary number activates “adding machine”, data buses and output latches. Finally the result is also a binary number and is stored in another register.
Although I give here a simple example of “add”, all different instructions go through the same FDE cycle. Due great speed of handling these numbers (one such operation is executed in nano seconds or micro seconds) controllers, and all digital devices work very fast.
An instruction is a binary number. Consider following examples of addition.
0010 1 r r r : This is an instruction that adds to accumulator register-contents of the register defined by “r r r” . Each “r” is replaced by 0 or 1. Suppose the last “r r r” combination is “0 1 0”, then it will mean that number in “r2 ” will be added to accumulator.
0010 0 1 0 0 c o n s t a n t : This is an instruction that adds to accumulator the constant given after the instruction (here this constant is an 8 bit number).
Carefully observe, that the code for “add” remains the same in both instructions (0010). This is the first (most significant) nibble. The next nibble decides the mode of addition and if necessary, the third byte comes as additional information. Using the order and binary information the meaning of the instruction is found out and then executed as described above.
If anything is convertible to a number, then it can be processed by a micro controller. This is after all a number game!