Reminds me of a memory corruption bug we encountered in our OS class. We were building a basic OS for a Cortex M3 board and we occasionally printed the wrong strings to the console despite having correct code and assembly. I forgot most of the details but basically we discovered our hardware (?) was not reentrant safe and our bug was caused by an interrupt handler overwriting our callstack. We "fixed" it by disabling interrupts while writing to the console.