Is there a way for a program to know if it's executed under the simulator and not on an actual CPU?
It would be simple to put a sim script in that watched for a particular variable / address to be written then modify it, invert it, or something else specific as desired. You likely would have ignore the zero init of the variable.
In the application, write this item then read it back - treating it as volatile. If it reads back different than written, it would indicate simulator.
This should be quite generic and not rely on specifics of the CPU, build configuration, or simulator flaws (features ) that do not exactly match the CPU.
Chad,
Yes, this is a good idea too. Its big advantage is that it's CPU-independent (I think you could use it with the 8051 as well), but the disadvantage is that it depends on a script that you have to create for every program that uses it.
Cheers, Sandy