The LC-3 – Chapter 6 COMP 2620 Dr. James Money COMP
Debugging When you drive to someplace new and you make a wrong turn, what do you do? There are two driving debugging techniques – Drive aimlessly hoping to find your way back – Return to some known position and use a map to compare where you are and where you should be
Debugging Debugging is similar to this in many ways The simplest way to keep track of where you are is to trace a program That is you keep track of the sequence of instructions that have been executed and the results it has produced
Debugging Another useful technique to divide your program into modules, similar to functions in a C program You can compare the results before and after each module to see if your code is executed properly and debug if needed
Debugging We will now look at the LC-3 simulator Using this program you can debug interactively as the program is running You can use the keyboard, monitor, and menus to control the simulator
Debugging We need to be able to: – Deposit values into memory and registers – Execute instruction sequences in a program – Stop execution when desired – Examine what is in memory and registers at any point in the program The LC-3 simulator allows all of these
Debugging There are three classes of errors: – Syntax Errors – Logic Errors – Data Errors
Debugging Syntax Errors – You made a typing error that resulted in an illegal operation. – Not usually an issue with machine language, because almost any bit pattern corresponds to some legal instruction. – In high-level languages, these are often caught during the translation from language to machine code.
Debugging Logic Errors – Your program is legal, but wrong, so the results don’t match the problem statement. – Trace the program to see what’s really happening and determine how to get the proper behavior.
Debugging Data Errors – Input data is different than what you expected. – Test the program with a wide variety of inputs.
Debugging There are three ways to debug a program: – Single stepping – Breakpoints – Watchpoints
Debugging Single-Stepping – Execute one instruction at a time. – Tedious, but useful to help you verify each step of your program.
Debugging Breakpoints – Tell the simulator to stop executing when it reaches a specific instruction. – Check overall results at specific points in the program. – Lets you quickly execute sequences to get a high-level overview of the execution behavior. – Quickly execute sequences that your believe are correct.
Debugging Watchpoints – Tell the simulator to stop when a register or memory location changes or when it equals a specific value. – Useful when you don’t know where or when a value is changed.