80 likes | 151 Views
ECE 447 - Lecture 21. Typical Assembly Language Program Bugs. Typical Assembly Language Program Bugs (1). 1. Improper transfer to subroutines. Correct: JSR, BSR Incorrect: JMP, BRA. 2. Forgetting to initialize stack pointer. section .bss rmb 128 stack_end.
E N D
ECE 447 - Lecture 21 Typical Assembly Language Program Bugs
Typical Assembly Language Program Bugs (1) 1. Improper transfer to subroutines Correct: JSR, BSR Incorrect: JMP, BRA 2. Forgetting to initialize stack pointer section .bss rmb 128 stack_end done by default by the startup code section .text lds #stack_end-1
Typical Assembly Language Program Bugs (2) 3. Not allocating enough memory for the stack program execution data data stack stack 4. Unbalanced stack operations just before RTS immediately after JSR SP variables RTN SP RTN
Typical Assembly Language Program Bugs (3) 5. Using subroutines that change registers Example: LDX #ADDRESS JSR changer LDAA 0,X 6. Transposed registers Examples: TBA vs. TAB PSHA PSHB PULX PSHB PSHA PULX instead of
Typical Assembly Language Program Bugs (4) 7. Not initializing pointer register Example: LDAA 0,X 8. Not initializing registers and data areas section .bss var1 rmb 2 Example: section .text LDD var1
Typical Assembly Language Program Bugs (5) 9. Inadvertent modification of the condition code register CLC start LDAA 0,X ADCA 0,Y STAA 0,X INX CPX #end BNE start Examples: CPX #end_address LDD result BNE start modifies Z flag modifies C flag
Typical Assembly Language Program Bugs (6) 10. Using the wrong conditional branch instruction Correct: for unsigned numbers for signed numbers BHI, BHS BLO, BLS BGT, BGE BLT, BLE 11. Using the wrong addressing mode Examples: INIT EQU 1 var1 fdb 5 LDD #var1 LDD INIT instead of LDD var1 instead of LDD #INIT
Typical Assembly Language Program Bugs (7) 12. Using a 16-bit counter in memory Example: counter fdb 0, 0 inc counter increments only the more significant byte of a 16-bit counter