Hardware Reference
In-Depth Information
variables of interest and their values at a certain time. It allows the user to find out
program execution results quickly at any breakpoint.
Trace program execution. Users can find out the execution result of a few instructions
by tracing instruction execution. Without a source-level debugger, it is very difficult
to trace the program execution unless the D-bug12 monitor commands are used.
The freeware EGNU and ICC12 IDE provide very little support for debugging. A commer-
cial source-level debugger for C language can cost thousands of dollars. Without a source-level
debugger, many debugging activities cannot be performed easily. CodeWarrior IDE provides
very useful and helpful features to support programming debugging.
There are several purposes for setting breakpoints.
To determine whether a segment of code has ever been entered by the CPU. The
programmer can use the embedded assembly instruction asm(swi) to find out with
a demo board programmed with the D-Bug12 monitor. Using the swi instruction
allows the programmer to find out where the program execution gets stuck and
identify the error.
To determine whether the execution result is correct up to the breakpoint. Without
a source-level debugger, the programmer can output the program execution result
to the LCD or terminal monitor to find out if the program executes correctly up to
the breakpoint. This also serves as a watch list for the program execution.
The following guidelines can help reduce and identify logic errors:
Make sure the precedence of operators has been observed.
Match the size of the source operands and that of the destination variables. Use
type casting when necessary. Type casting has been used in several examples in
this text.
Walk through the program algorithm carefully before converting it into the
program code. An incorrect algorithm is often the cause of program bugs.
Use enough data to test the program. The program must be tested with normal inputs,
maximum and minimum inputs, and also the illegal inputs to make sure that it operates cor-
rectly under all circumstances. When the problem to be solved gets complicated, a structured
programming approach should be used to organize the program. The guidelines described in
Section 2.4 should be followed to develop the program algorithm and convert the algorithm
into program code. Each individual function should be tested thoroughly before the whole pro-
gram is tested. A comprehensive discussion of structured programming and testing is beyond
the scope of this text but can be found in many textbooks on software engineering.
5.15 Summary
A C program consists of one or more functions and variables. The main ( ) function is re-
quired in every C program. It is the entry point of a C program. A function contains statements
that specify the operations to be performed. The types of statements in a function could be dec-
laration , assignment , function call , control , and null .
A variable stores a value to be used during the computation. A variable must be declared
before it can be used. The declaration of a variable consists of the name and the type of the vari-
able. There are four basic data types in C: char , int , float , and double . Several qualifiers can be
added to the variable declarations. They are short , long , signed , and unsigned .
 
Search WWH ::




Custom Search