ece 447 - lecture 21 typical assembly language program bugs
TRANSCRIPT
![Page 1: ECE 447 - Lecture 21 Typical Assembly Language Program Bugs](https://reader036.vdocuments.site/reader036/viewer/2022082518/5697bfd81a28abf838caeb7c/html5/thumbnails/1.jpg)
ECE 447 - Lecture 21
Typical Assembly LanguageProgram Bugs
![Page 2: ECE 447 - Lecture 21 Typical Assembly Language Program Bugs](https://reader036.vdocuments.site/reader036/viewer/2022082518/5697bfd81a28abf838caeb7c/html5/thumbnails/2.jpg)
Typical Assembly Language Program Bugs (1)
1. Improper transfer to subroutines
Correct: JSR, BSRIncorrect: JMP, BRA
2. Forgetting to initialize stack pointer
section .text
lds #stack_end-1
done by default by the startup code
section .bss rmb 128stack_end
![Page 3: ECE 447 - Lecture 21 Typical Assembly Language Program Bugs](https://reader036.vdocuments.site/reader036/viewer/2022082518/5697bfd81a28abf838caeb7c/html5/thumbnails/3.jpg)
Typical Assembly Language Program Bugs (2)
3. Not allocating enough memory for the stack
4. Unbalanced stack operations
immediately after JSR just before RTS
RTNRTNSP
SP
data
stack
data
stack
programexecution
variables
![Page 4: ECE 447 - Lecture 21 Typical Assembly Language Program Bugs](https://reader036.vdocuments.site/reader036/viewer/2022082518/5697bfd81a28abf838caeb7c/html5/thumbnails/4.jpg)
Typical Assembly Language Program Bugs (3)
5. Using subroutines that change registers
LDX #ADDRESS
JSR changer
LDAA 0,X
Example:
6. Transposed registers
TBA vs. TAB
PSHAPSHBPULX
Examples:
instead ofPSHBPSHAPULX
![Page 5: ECE 447 - Lecture 21 Typical Assembly Language Program Bugs](https://reader036.vdocuments.site/reader036/viewer/2022082518/5697bfd81a28abf838caeb7c/html5/thumbnails/5.jpg)
Typical Assembly Language Program Bugs (4)
7. Not initializing pointer register
8. Not initializing registers and data areas
section .bssvar1 rmb 2
LDAA 0,X
section .text
LDD var1
Example:
Example:
![Page 6: ECE 447 - Lecture 21 Typical Assembly Language Program Bugs](https://reader036.vdocuments.site/reader036/viewer/2022082518/5697bfd81a28abf838caeb7c/html5/thumbnails/6.jpg)
Typical Assembly Language Program Bugs (5)
9. Inadvertent modification of the condition code register
CPX #end_addressLDD resultBNE start
Examples: CLCstart LDAA 0,X ADCA 0,Y STAA 0,X INX CPX #end BNE start
modifies Z flag
modifies C flag
![Page 7: ECE 447 - Lecture 21 Typical Assembly Language Program Bugs](https://reader036.vdocuments.site/reader036/viewer/2022082518/5697bfd81a28abf838caeb7c/html5/thumbnails/7.jpg)
Typical Assembly Language Program Bugs (6)
10. Using the wrong conditional branch instruction
BHI, BHSBLO, BLS
for unsigned numbers
Correct:
BGT, BGEBLT, BLE
for signed numbers
11. Using the wrong addressing mode
Examples:
LDD INIT
INIT EQU 1 var1 fdb 5
LDD #var1
instead of
LDD #INIT
instead of
LDD var1
![Page 8: ECE 447 - Lecture 21 Typical Assembly Language Program Bugs](https://reader036.vdocuments.site/reader036/viewer/2022082518/5697bfd81a28abf838caeb7c/html5/thumbnails/8.jpg)
Typical Assembly Language Program Bugs (7)
12. Using a 16-bit counter in memory
counter fdb 0, 0
inc counter
Example:
increments only the more significantbyte of a 16-bit counter