Debugging a machine level program

Debugging is the process of identifying and removing bug from software or program. It refers to identification of errors in the program logic, machine codes, and execution. It gives step by step information about the execution of code to identify the fault in the program.

Debugging of machine code: Translating the assembly language to machine code is similar to building a circuit from a schematic diagram. Debugging can help in determining:

  • Values of register.
  • Flow of program.
  • Entry and exit point of a function.
  • Entry into if or else statement.
  • Looping of code.
  • Calculation check.

Common sources of error:

  • Selecting a wrong code
  • Forgetting second or third byte of instruction
  • Specifying wrong jump locations
  • Not reversing the order of high and low bytes in a Jump instruction
  • Writing memory addresses in decimal instead of hexadecimal
  • Failure to clear accumulator when adding two numbers
  • Failure to clear carry registers
  • Failure to set flag before Jump instruction
  • Specifying wrong memory address on Jump instruction
  • Use of improper combination of rotate instructions

The debugging process is divided into two parts:

  1. Static Debugging: It is similar to visual inspection of circuit board, it is done by a paper and pencil to check the flowchart and machine codes. It is used to the understanding of code logic and structure of program.
  2. Dynamic Debugging: It involves observing the contents of register or output after execution of each instruction (in single step technique) or a group of instructions (in breakpoint technique).
    In a single board microprocessor, techniques and tools commonly used in dynamic debugging are:

    1. Single Step: This technique allows to execute one instruction at a time and observe the results of each instruction. Generally, this is build using hard-wired logic circuit. As we press the single step run key we will be able to observe the contents of register and memory location. This helps to spot:
      • incorrect addresses
      • incorrect jump location in loops
      • incorrect data or missing codes

      However, if there is large loop then single step debugging can be very tiring and time-consuming. So instead of running the loop n times, we can reduce the number of iteration to check the effectiveness of the loop. The single step technique is very useful for short programs.

    2. Breakpoint: The breakpoint facility is usually a software routine that allows users to execute a program in sections. The breakpoints can be set using RST instruction. When we push the Execute key, the program will be executed till the breakpoint. The registers can be examined for the expected result. With the breakpoint facility, isolate the segment of program with errors. Then that segment can be debugged using the single-step facility. It is usually used to check:
      • Timing loop
      • I/O section
      • Interrupts
    3. Register Examine: The register examine key allows you to examine the contents of the microprocessor register. This technique is used in conjunction with either single-step or breakpoint facility.


My Personal Notes arrow_drop_up

Student at Netaji Subhas Institute of Technology

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.