Sun, 20 Oct 2013, 12:58
My students, This question re: debugging might be helpful so I am forwarding to you all. A student writes: > Dr Patt, > > My question is my program seems to be running none-stop. It is functioning > in a loop and never reaching the HALT instruction. Is there a better way to > check where the problem is without performing the program step by step? > > Thank you for replying, > << name withheld to protect the student who does not want to single step>> Sure, it is no fun single-stepping 100 lines of program. Less fun if it is 10,000 lines of program. Let's assume your code looks like: STARTOFLOOP instruction 1 instruction 2 ... instruction 100 A BRz STARTOFLOOP ... How about setting a breakpoint at A. Your program will execute the 100 instructions, and then you can examine various contents to see what you messed up. If you find it, you fix it and move on. Suppose you do not find it. Then what? STARTOFLOOP instruction 1 instruction 2 ... B instruction 51 ... instruction 100 A BRz STARTOFLOOP ... Set a breakpoint at B. Restart your program from the beginning. Now only the first 50 instructions will execute before the breakpoint causes execution to stop. Examine relevant contents. Is everything cool? In this way, you can zero in on the problem much more quickly than single step. Last resort: Single step! Usually the best place to set these breakpoints is at branch instructions so you can check to see if the condition codes have been set according to the way you think they should be set. Also, you may have to do a few iterations with the same breakpoint before the cause of the problem jumps out at you. The main point of this email is you do not have to tediously single step, but with breakpoints you can get the computer to execute some number of instructions for you before stopping. Hope this helps. Good luck finishing it today. Yale Patt