I am learning the Cortex-M with the MDK uVision IDE. I wrote a simple SysTick_Handler() to replace the WEAK default SysTick_Handler() which is a simple dead loop.
My SysTick_Handler():
The disassembly:
I am confused by the the highlighted assembly line. It is simply a dead loop.
Why is it there? Why the toolchain still generated it despite that I already overwrite the WEAK default implementation with my own SysTick_Handler?
I can still place a breakpoint at that line and it can be hit. And in that case, my code will never be executed.
But strange thing is, if I removed the breakpoint at that line, my code can then be reached. How is that possible?


(Thanks to all the hints the community provided. I think I can explain it now.)
The dead loop is part of my
main()function, which is like below. Themain()function is just above mySysTick_Handlerin the same C file.To double confirm, I modified the while loop to below:
The generated code is like this now:
Though it is still placed under the
SysTick_Handler. I place a break point there to check what's really going on:The
R1is the constant0x12345. TheR0is the local variablejj. We can see theR1does contain the landmark value0x12345, which is added toR0(jj). So it must be part of mywhile(1)loop in themain().So, the disassembly is correct. Only that the debugger failed to provide a correct interleaving between the source and the disassembly.
And btw, remember to rebuild the target after modifying the code otherwise the uVision IDE debugger will not reflect the latest change....