Presentation is loading. Please wait.

Presentation is loading. Please wait.

ECE 447 - Lecture 21 Typical Assembly Language Program Bugs.

Similar presentations


Presentation on theme: "ECE 447 - Lecture 21 Typical Assembly Language Program Bugs."— Presentation transcript:

1 ECE 447 - Lecture 21 Typical Assembly Language Program Bugs

2 Typical Assembly Language Program Bugs (1) 1. Improper transfer to subroutines Correct: JSR, BSR Incorrect: JMP, BRA 2. Forgetting to initialize stack pointer section.text lds #stack_end-1 done by default by the startup code section.bss rmb 128 stack_end

3 Typical Assembly Language Program Bugs (2) 3. Not allocating enough memory for the stack 4. Unbalanced stack operations immediately after JSR just before RTS RTN SP data stack data stack program execution variables

4 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 PSHA PSHB PULX Examples: instead of PSHB PSHA PULX

5 Typical Assembly Language Program Bugs (4) 7. Not initializing pointer register 8. Not initializing registers and data areas section.bss var1 rmb 2 LDAA 0,X section.text LDD var1 Example:

6 Typical Assembly Language Program Bugs (5) 9. Inadvertent modification of the condition code register CPX #end_address LDD result BNE start Examples: CLC start LDAA 0,X ADCA 0,Y STAA 0,X INX CPX #end BNE start modifies Z flag modifies C flag

7 Typical Assembly Language Program Bugs (6) 10. Using the wrong conditional branch instruction BHI, BHS BLO, BLS for unsigned numbers Correct: BGT, BGE BLT, BLE for signed numbers 11. Using the wrong addressing mode Examples: LDD INIT INIT EQU 1var1 fdb 5 LDD #var1 instead of LDD #INIT instead of LDD var1

8 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 significant byte of a 16-bit counter


Download ppt "ECE 447 - Lecture 21 Typical Assembly Language Program Bugs."

Similar presentations


Ads by Google