Open In App

Debugging a machine level program

Improve
Improve
Like Article
Like
Save
Share
Report

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 a large loop, single-step debugging can be very time-consuming. So, instead of running the                       loop n times, we can reduce the number of iterations 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.

The following table summarizes the techniques and tools commonly used in debugging a machine-level program:

Debugging Technique Description
Static Debugging  Using a paper and pencil to check the flowchart and machine codes to understand the code logic and the structure of the program.
Single step Allowing the execution of one instruction at a time and observing the contents of registers and memory location after each instruction.
Breakpoint Setting breakpoints using the RST instruction and executing the program until the breakpoint. Registers can be examined for the expected result.
Register Examine Examining the contents of the microprocessor register in conjunction with either single-step or breakpoint

Last Updated : 20 Apr, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads