Presentation is loading. Please wait.

Presentation is loading. Please wait.

ECE 447: Lecture 16 Common Errors & Good Programming Style.

Similar presentations


Presentation on theme: "ECE 447: Lecture 16 Common Errors & Good Programming Style."— Presentation transcript:

1 ECE 447: Lecture 16 Common Errors & Good Programming Style

2 Typical Assembly Language Program Bugs

3 ECE 447: Typical Assembly Language Program Bugs 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 when you call your assembly language routine from the main() function written in C section.bss rmb 128 stack_end

4 ECE 447: Typical Assembly Language Program Bugs 3. Not allocating enough memory for the stack data stack data stack program execution

5 ECE 447: Typical Assembly Language Program Bugs 4. Unbalanced stack operations immediately after JSR just before RTS RTN SP variables

6 ECE 447: Typical Assembly Language Program Bugs 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

7 ECE 447: Typical Assembly Language Program Bugs 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:

8 ECE 447: Typical Assembly Language Program Bugs 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

9 ECE 447: Typical Assembly Language Program Bugs 10. Using the wrong conditional branch instruction BHI, BHS BLO, BLS for unsigned numbers Correct: BGT, BGE BLT, BLE for signed numbers

10 ECE 447: Branch Instructions (1) REL N Z V C – – after comparison register vs. memory unsigned numberssigned numbers BHI higher > BLO lower < BHS higher or same  BLS lower or same  BGT greater than > BLT less than < BGE greater than or equal  BLE less than or equal  BEQ equal = BNE not equal 

11 ECE 447: Typical Assembly Language Program Bugs 11. Using the wrong addressing mode Examples: LDD INIT INIT EQU 1var1 fdb 5 LDD #var1 instead of LDD #INIT instead of LDD var1

12 ECE 447: Typical Assembly Language Program Bugs 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!

13 Good Programming Style

14 ECE 447: Do Not Use Magic Constants! // set EGA PIOC |= EGA; // clear STAI PIOC &= ~STAI; PIOC |= 0x40; PIOC &= 0xBF; Bad styleGood style #include

15 ECE 447: Do Not Use Magic Constants! Bad styleGood style #include while (!(TFLG2 & TOF)) ; while ((TFLG2 & 0x80)==0) ; while ((TFLG2 & TOF) == 0) ; // do nothing while TOF equal to 0 or while (!(TFLG2 & 0x80)) ;

16 ECE 447: Do Not Use Magic Constants! Bad styleGood style PIOC_STAI EQU $40 PIOC_EGA EQU $20 // set EGA LDAA PIOC ORAA #EGA STAA PIOC // clear STAI LDAA PIOC ANDA #~STAI STAA PIOC PIOC EQU $1002 LDAA $1022 ORAA #$02 STAA $1022 LDAA $1022 ANDA #$BF STAA $1022

17 ECE 447: Initializing global variables Bad practice Good practice int counter = 0; char lookup[3]; int counter; void main(void) { counter = 0; } const char lookup[] = {0xE6, 0xE4, 0xEA}; const char string1 = “Menu:”; main() { lookup[0] = 0xE6; lookup[1] = 0xE4; lookup[2] = 0xEA; } char string1[5]= {‘M’,’e’,’n’,’u’,’:’};

18 ECE 447: Clearing Timer Flags TMSK 1 &= ~OC2F; Clears all flags in the same byte except OC2F or TMSK1 |= OC2F Clears all flags in the same byte, including OC2F BadGood #include TMSK1 = OC2F Clears only OC2F

19 ECE 447: Common errors regarding interrupts C ASM No __attribute__((interrupt)) in the declaration/prototype of an interrupt service routine Using RTS instead of RTI Using local auto variables to store information between interrupts Calling an interrupt service routine in your program (allowed only for testing after commenting __attribute__((interrupt)) modifier)

20 ECE 447: Common errors regarding interrupts C & ASM No CLI No setting of the local interrupt enable flag Waiting for a flag to be set INSIDE of an interrupt

21 ECE 447: Common errors regarding polling C Using if instead of while to wait for a flag to be set No clearing the flag after it was set No using of special procedure to clear the flag Not disabling interrupts Checking the wrong flag

22 ECE 447: Common errors regarding polling ASM Using too complicated procedure to check the flag LOOP LDAA PIOC ANDA #STAF CMPA #0 BEQ LOOP LOOP TST PIOC BPL LOOP Bad styleGood style

23 ECE 447: Use but not abuse comments LDAA #INIT ; load accumulator A with ; the constant INIT STAA COUNTER ; store accumulator A to the variable COUNTER Useless and repetitive Effective ; initialize COUNTER to INIT LDAA #INIT STAA COUNTER

24 VHDL: - writing synthesizable RTL level code in VHDL - writing test benches FPGAs: - architecture of FPGA devices - tools for the computer-aided design with FPGAs - current FPGA families & future trends Topics ECE 448, FPGA and ASIC Design with VHDL Applications: - basics of computer arithmetic - applications from communications, cryptography, digital signal processing, bioengineering, etc.

25 - FPGA boards - microprocessor board–FPGA board interfaces: PCI, PCI-X, PCIe, JTAG, USB - reconfigurable computers High-level ASIC Design: - standard cell implementation approach - logic synthesis tools - differences between FPGA & standard-cell ASIC design flow New trends: - using high-level programming languages to design hardware - microprocessors embedded in FPGAs Platforms:

26 Tasks of the course Advanced course on digital system design with VHDL Comprehensive introduction to FPGA & front-end ASIC technology Testing equipment - writing VHDL code for synthesis - design using finite state machines and algorithmic state machines - test benches - hardware: Xilinx FPGAs, TSMC library of standard ASIC cells - software: VHDL simulators Synthesis tools Xilinx ISE - oscilloscopes - logic analyzer

27 Celoxica RC10 Educational Board

28

29

30

31 Digital system design technologies coverage in the CpE & EE programs at GMU Microprocessors ASICs FPGAs ECE 445 ECE 447 ECE 586 ECE 681 ECE 448 ECE 511 ECE 611 ECE 431 Computer Organization Single Chip Microcomputers FPGA and ASIC Design with VHDL Digital Circuit Design Microprocessors Advanced Microprocessors Digital Integrated Circuits VLSI Design Automation ECE 545 Introduction to VHDL ECE 645 Computer Arithmetic


Download ppt "ECE 447: Lecture 16 Common Errors & Good Programming Style."

Similar presentations


Ads by Google