While preparing for an exam, I came across this doubt. Does a CPU process instructions as data?
Asked
Active
Viewed 186 times
0
-
Can you expand on what you mean? – GHC Apr 08 '13 at 17:49
-
So there is a (for example an assembly) instruction, LDA $04. It would look like 90 04 in machine code and 10010000 00000100 in binary. So does cpu can process it as data? – InsulT Apr 08 '13 at 17:56
-
Absolutely. "Code is data" is a common phrase in some parts of the software industry. – Dave Newman Apr 08 '13 at 18:05
2 Answers
2
The short answer is yes. There's a Wikipedia entry on it. The gist of it is, if you have the address of the instructions you would like to read, then you can load those into data registers, test the instructions, and even write back new instructions. Many modern operating systems will probably not allow you write the instructions back however. It is a safety precaution to prevent malicious code from modifying your system, or trust applications.

Ry-
- 218,210
- 55
- 464
- 476

Dave Newman
- 1,018
- 10
- 15
1
Depends on the computer:
In von Neumann architecture, yes.
In Harvard architecture, no.

NPE
- 486,780
- 108
- 951
- 1,012