ch06 Inclass 02 Debugging
ch06 Inclass 02 Debugging
Debugging
You’ve written your program and it doesn’t work.
Now what?
6-2
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Debugging Operations
Any debugging environment should provide means to:
1. Display values in memory and registers.
2. Deposit values in memory and registers.
3. Execute instruction sequence in a program.
4. Stop execution when desired.
Types of Errors
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.
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.
Data Errors
• Input data is different than what you expected.
• Test the program with a wide variety of inputs.
6-4
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Example 1: Multiply
This program is supposed to multiply the two unsigned
integers in R4 and R5.
clear R2
x3200 0101010010100000
x3201 0001010010000100
add R4 to R2
x3202 0001101101111111
decrement R5
x3203 0000011111111101
x3204 1111000000100101
No
R5 = 0?
Set R4 = 10, R5 =3.
Yes
Run program.
HALT Result: R2 = 40, not 30.
6-6
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
x3107 x0019
x3108 x0007 Loading contents of M[x3100], not address.
Change opcode of x3003
x3109 x0004 from 0010 (LD) to 1110 (LEA).
6-9
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
6-13
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
6-14