Curious
Curious

Reputation: 63

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?

Upvotes: 3

Views: 1530

Answers (2)

Nefrin
Nefrin

Reputation: 338

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.

Upvotes: 2

JCollier
JCollier

Reputation: 1179

The way the computer distinguishes between instructions and numbers simply depends on what is reading the data and where. For example, a simple Arithmetic Logic Unit (ALU) will include an input for the operation to be done, and two inputs for the operands. The data going into the operand ports is read as numbers, whereas the data going into the operator input is read as an instruction.

It all depends on what computer architecture unit is reading the data, and on what input that unit is reading it.

Upvotes: 0

Related Questions