I've been programming for around 35 years in total (a huge amount in machine code), and in all that time I haven't come across something quite as odd as what is happening with some assembler AVR code I am working on.
To cut a long story short, there are two sets of code, set A, which works fine, as normal, and then there is set B, which I developed from A, which works fine, UNTIL I remove and re-apply power from the ATMega device a few times, and then it stops working.
I have dumped out the Flash contents both before and after the device stops working, and they are both identical! (I have already made sure the brown-out detector is enabled to prevent any possible FLASH corruption.)
I was always under the impression that a device would start from power up into a known state, so if the Flash is not corrupted, why does the software fail after so many restarts when it worked fine before?
I can't find any registers or hardware which start in an unknown state which would affect the code.
I have started to painstakingly remove and replace sections of code to isolate this bug, which has me worried about the design of the AVR. Not only do I now have to test my code, but after a development phase, repeatedly remove and re-apply power to the device to ensure that it is stable.
Is anyone aware of any known hardware bugs such as the execution of a certain sequence of instructions or maybe interrupt or other hardware glitches which could cause an AVR to enter a confused state which a power off - on would not clear?
If I ever do find the culprit of course I will be delighted to post it on here so others can see if they can subject it to empirical scientific analysis!
In the meantime I will continue to beaver away using a process of elimination - just hope that I don't go mad in the meantime...