Explain how you would debug a hard fault or segmentation fault on a bare-metal microcontroller using only register outputs.