When the CPU reads a memory location or a block of memory, it fetches something like this:-
1011001 11001100 11101010 00110110 01101111 00001110
the only way to interpret this "data" is to know what the CPU is expecting.
HenryCase wrote:
I would like to pick up on one point which has been stated by you both in the past, which is that there isn't a way to distinguish between instructions and data.
Every program has a start point and the CPU knows this start address WILL be an instruction (opcode) but the second byte maybe another opcode or it could be data.
According to Wikipedia, the following four steps are used in classical CPU architecture: fetch, decode, execute, writeback. The second step 'decode' is of interest to us here. Again, according to Wikipedia:
.....
So for even the most basic program to function the CPU must know the difference between the opcode part of the instruction and the operand part of the instruction. Can we agree on that at least?
So the only way for the operating system to know if a byte contains an opcode or data is to emulate the cpu in software and follow the execution of the program from the start, which will be very slow, it cannot simply read a byte and know whether it has fetched an opcode or data.