Hi, How is a processor able to differentiate the numbers as either data or instructions ? Thx in advans, Karthik Balaguru
Differentiate the numbers as either data or instructions
Started by ●October 21, 2007
Reply by ●October 21, 20072007-10-21
"karthikbalaguru" <karthikbalaguru79@gmail.com> wrote in message news:1192956657.375752.263790@t8g2000prg.googlegroups.com...> Hi, > > How is a processor able to differentiate the numbers as either data or > instructions ? > > Thx in advans, > Karthik BalaguruSome 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 by ●October 21, 20072007-10-21
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 On Oct 21, 4:50 am, karthikbalaguru <karthikbalagur...@gmail.com> wrote:> Hi, > > How is a processor able to differentiate the numbers as either data or > instructions ? > > Thx in advans, > Karthik Balaguru
Reply by ●October 21, 20072007-10-21
"karthikbalaguru" <karthikbalaguru79@gmail.com> wrote in message news:1192956657.375752.263790@t8g2000prg.googlegroups.com...> Hi, > > How is a processor able to differentiate the numbers as either data or > instructions ?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 by ●October 21, 20072007-10-21
karthikbalaguru wrote:> Hi, > > How is a processor able to differentiate the numbers as either data or > instructions ? >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 by ●October 21, 20072007-10-21
On Sun, 21 Oct 2007 01:50:57 -0700, karthikbalaguru <karthikbalaguru79@gmail.com> wrote:>How is a processor able to differentiate the numbers as either data or >instructions ?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 by ●October 21, 20072007-10-21
karthikbalaguru wrote:> Hi, > > How is a processor able to differentiate the numbers as either data or > instructions ?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 by ●October 21, 20072007-10-21
Vladimir Vassilevsky wrote:> "karthikbalaguru" <karthikbalaguru79@gmail.com> wrote in message > news:1192956657.375752.263790@t8g2000prg.googlegroups.com... >> Hi, >> >> How is a processor able to differentiate the numbers as either data or >> instructions ? > > > 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.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 by ●October 21, 20072007-10-21
"Jerry Avins" <jya@ieee.org> wrote in message news:_N6dnSyIkb0RH4banZ2dnUVZ_ournZ2d@rcn.net...> Vladimir Vassilevsky wrote: >> "karthikbalaguru" <karthikbalaguru79@gmail.com> wrote in message >> news:1192956657.375752.263790@t8g2000prg.googlegroups.com... >>> Hi, >>> >>> How is a processor able to differentiate the numbers as either data or >>> instructions ? >> >> >> 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. > > 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. > > JerryNot 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 by ●October 21, 20072007-10-21
On 2007-10-21, karthikbalaguru <karthikbalaguru79@gmail.com> wrote:> > How is a processor able to differentiate the numbers as either data or > instructions ?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






