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:
- 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.
- 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
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:
||Using a paper and pencil to check the flowchart and machine codes to understand the code logic and the structure of the program.
||Allowing the execution of one instruction at a time and observing the contents of registers and memory location after each instruction.
||Setting breakpoints using the RST instruction and executing the program until the breakpoint. Registers can be examined for the expected result.
||Examining the contents of the microprocessor register in conjunction with either single-step or breakpoint
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses
are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!