Differentiate the numbers as either data or instructions

Hi,

How is a processor able to differentiate the numbers as either data or instructions ?

Thx in advans, Karthik Balaguru

Reply to
karthikbalaguru
Loading thread data ...

Some processors have separate data and instruction buses, and some protection mechanisms to generate exceptions, but other than that, it cant differentiate between the two. It just does with the 'numbers' what your software tells it to do. If you set the program counter to an address that was within data it would attempt to execute the data.

--
Regards,
Richard.

+ http://www.FreeRTOS.org
13 official architecture ports, 1000 downloads per week.

+ http://www.SafeRTOS.com
Certified by TÜV as meeting the requirements for safety related systems.
Reply to
FreeRTOS.org

It's essentially part of the compiler and the hardware memory management to store code in one place and data in another, that's the only difference. The expectation is that the code is such that any jumps and branches only go from one code memory location to another. Thus, it is conceptually possible to execute something from data, though the resulting instruction may or may not be meaningful.

The exception is a Harvard architecture which has a separate memory for data and instructions. This is common in microcontrollers. But most more advanced processors use the Von Neumann (sp?) architecture where data and code memory is combined.

Chris

Reply to
Chris Maryan

If somebody asks a really clueless question in a technical newsgroup, it is

90% chance that it is a Balamalagurumuru or a Abdulgazizhamid. I don't think that Balamalagurumurus and Abgulgazizhamids are inferior to Johns Smiths; most likely it tells that Johns Smiths don't want to go to school.

VLV

Reply to
Vladimir Vassilevsky

Hope you don't mind the question (Sunday morning diversion, I suppose) but are there a number of different people posting under the moniker 'karthikbalaguru'? Some posts are like this one (terse and non-specific) and others are very verbose, with different grammatical styles and more specific content. Perhaps this account is in a classroom somewhere?

BTW, why so many crossposted groups?

Regards,

Michael

Reply to
msg

It shouldn't differentiate instructions or data if you want to write self modifying code. Stupid inventions, such as the Harvard architecture make it hard or even impossible to write such creative programs :-).

Paul

Reply to
Paul Keinanen

Any stored element can be either. It depends on the structure of the program. You really should address this question to a group that deals more directly with how computers work, rather than what they work on.

A related question is treating data as numbers or as text. The answer is always the same.

Jerry

--
Engineering is the art of making what you want from things you can get.
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Reply to
Jerry Avins

Clueless is better than willfully ignorant. When a recent graduate (Master of Computer Science) heard that I actually designed computers, he asked me how they distinguish between ASCII and numbers. He dismissed me as an ignoramus when I told him that the distinction isn't made in hardware.

Jerry

--
Engineering is the art of making what you want from things you can get.
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Reply to
Jerry Avins

Not all Computer Scientists are completely clueless, just many of them.

Unfortunately, most of the Computer Scientists I have the misfortune to have to deal with know nothing about either computers or science. They seem to have a liberal arts degree in high level languages. They seem to think that it is more important to have the documentation their way than for the program to work!

Documentation their way doesn't use flow charts, they are out of style. To me, flow charts show the flow of the program, the decisions made, and in what order.

They tell management that assembly language programming should never be allowed as it is too cryptic. To me, some HOL programmers take great pride in doing as much as possible in one instruction which makes it very cryptic!

They tell management that my program structure is wrong. They say that I should not have a separate initialization section. I say that proper initialization is VERY important. Some of my programs operate destruct systems. Even though the S&A devices are multi step with delays, they need to be commanded to full safe. People will die if the destruct system unexpectedly goes off.

Don

Reply to
Donald Harris

In a word, context. In a Von Neumann architechure, there is no fundamental difference between the two. It is only that code should usually only ever branch to code, and not to data. On reset, the processor will begin executing at some predefined memory location, and things are contrived such that that location contains code. It is the responsibility of it and other code to ensure that execution only ever passes to more code and not data. In reality this requirement usually isn't particularly onerous as you only ever want to branch to a particular routine that performs the required task, not to some random code.

There are, however, one or two fringe cases where data can be code or vice versa. The first useful case is self modifying code as has already been mentioned, although nowadays that is usually regarded as a Bad Thing everywhere except possibly the embedded world, and even here you have to be careful if the processor has separate instruction and data caches.

The second useful case, and somewhat more common, is initial program load on a disk-based system. When the program is read off disk, it is initially regarded as data. After setting up the program's memory map, linking in any dynamic libraries and anything else that needs doing, that data is then regarded as code, control is passed to it and your program starts running.

Less desirable is the vulnerability caused by this ambiguity to running user-supplied code/data - this is a powerful mechanism for crackers. Here, the general idea is to stuff a data buffer with code that will cause the desired effect, and then fooling the program into passing control to that data. This is why it is a Good Thing if your MMU can mark pages non-executable, so that an error is caused if this kind of thing is attempted.

--
Andrew Smallshaw
andrews@sdf.lonestar.org
Reply to
Andrew Smallshaw

For the most popular computers today... it doesn't.

Computers store numbers in addressed locations in memory. When the "program counter" is set to an address and the processor executes the number at the address, it is an instruction. When a program loads a value from the same address into a processor register, it is data.

But generally speaking if you look at a number somewhere in memory you can't tell whether it is data or an instruction. It is how the number is used that defines it as data or instruction.

Regards, Steve

Reply to
Steve

That is why von neuman is famous and you aren't. Don't feel bad, I'm not either.

Reply to
Del Cecchi

It isn't. It's the program that's running on the processor has to make the differentiation. However there are also cases where it doesn't. Search for these terms: microsoft buffer overflow remote code execution

Reply to
Tom

-- snip snip

The irony here is delicious. The original VN architecture had no address calculation capability - in particular no index registers. Treating an instruction as data - adding or subtracting a value to from its address field was the only way - other than having a distinct instruction with the appropriate address in it - to access multiple elements of an array or other data structure.

As soon as our cousins across the sea invented address modification registers - b lines - that was no longer necessary.

To be an effective computer the original VN arch had to interpret the contents of (some) memory locations as both instructions and data.

JKA

--
How do you tighten a screw? Turn it until the thread strips
and then back it off a quarter of a turn?
Reply to
John Ahlstrom

Y'all are forgetting about tagged architectures, which check the tag of the memory word before using what was read, or writing to it. e.g. Unisys Libra series.

- Tim

Reply to
Tim McCaffrey

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.