This week I spent about five hours tracking a strange bug in a
program with over 2000 lines. I had several inline assembler
procedures which manipulate data in several arrays, and always
the same array at the same position was overwritten with two
bytes of data I had no idea where they came from.
Finally I discovered by accident, that these strange two bytes,
taken together as an integer value, corresponded exactly to the
value of a line number I had inserted between two assembler
statements for error tracking purposes. It looked somehow like
this:
You won't believe it: I removed the line number (8020), and everything
worked perfectly!!
Now this leads me to some questions, of course:
- Is it an error to insert line numbers between assembler statements?
- How does the compiler interpret resp. misinterpret this number?
(I am still not able to explain how the value of the line number gets
into a data array when the code is executed.)
- If it is an error, why does this code compile without an error message?
- Does it make sense at all to apply ERR and ERL to code written in
inline Assembler? (I thought at least some errors, such as numeric
errors or disk write errors, could be trapped like that, but maybe I am
wrong. The program referred to makes heavy use of conventional memory,
so I cannot run it in PBD.)
I hope somebody can enlighten me about this point.
Thank you!
Hans Ruegg
program with over 2000 lines. I had several inline assembler
procedures which manipulate data in several arrays, and always
the same array at the same position was overwritten with two
bytes of data I had no idea where they came from.
Finally I discovered by accident, that these strange two bytes,
taken together as an integer value, corresponded exactly to the
value of a line number I had inserted between two assembler
statements for error tracking purposes. It looked somehow like
this:
Code:
... ! CLD ! LDS SI, CS:currentPtr ;(this is a CS variable declared earlier) 8020 '(this is the line number causing the bug) MyLoop: ! LODSB ! XOR AH,AH ! TEST AL, 1 ...
worked perfectly!!
Now this leads me to some questions, of course:
- Is it an error to insert line numbers between assembler statements?
- How does the compiler interpret resp. misinterpret this number?
(I am still not able to explain how the value of the line number gets
into a data array when the code is executed.)
- If it is an error, why does this code compile without an error message?
- Does it make sense at all to apply ERR and ERL to code written in
inline Assembler? (I thought at least some errors, such as numeric
errors or disk write errors, could be trapped like that, but maybe I am
wrong. The program referred to makes heavy use of conventional memory,
so I cannot run it in PBD.)
I hope somebody can enlighten me about this point.
Thank you!
Hans Ruegg
Comment