I remember I had a OS bug in my realtime class where I didn't same the ARM core's flags that get set of the compare operations.
In arm, it's two instructions to do something like `if (x > 3) { blah; }`. First do a subtract of 3 and x, and this will set the NZCV flags. If the result of `3-x` is negative, the N flag will be set.
Then do a branch if N instruction afterwards.
https://developer.arm.com/documentation/dui0801/g/Condition-...
So if there was a context switch / interrupt between the two steps, my code would take the wrong if arm. So I'd get things like
if (x > 0) {
y = 5 / x;
}
throwing a divide by zero error, which was super confusing. And I could work around it by doing if (x > 0) {
if (x > 0) { // For real this time
y = 5 / x;
}
}
since it was very unlikely to happen twice in a row.Eventually I fixed it, but that was fun.