cpu-architecturevon-neumann

How does a computer distinguish whether a binary pattern is an instruction or just a number?


I am reading the book "Computer Organization and Embedded Systems" by Hamacher and my question is: "How does a computer distinguish whether a binary pattern is an instruction or just a number?"

Can anyone help me understand that concept?


Solution

  • A Von Neumann Processor (pretty much any processor out there) can not distinguish between code and data in memory. What ever the instruction pointer of the CPU points to will be loaded into the instruction decoder as an instruction. If it is not a valid instruction it will raise an exception in the CPU.

    This enables a program to create new executable code in memory or even change its own code. On the other hand this enables many code injection attacks.