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

Slides:



Advertisements
Similar presentations
Chapter 8: Central Processing Unit
Advertisements

EE 362 Microprocessor Systems and Interfacing © 1-1 Lecture 1: Introduction to Microprocessor Based Systems Microprocessor Architecture Microprocessor.
Processor Function Topic 3.
ELEC 330 Digital Systems Engineering Dr. Ron Hayne
EET 2261 Unit 5 Tables; Decision Trees & Logic Instructions
Assembler Programming Chapter 6. EEL-4746 Best Practices.
68HC11 Polling and Interrupts
COMP3221: Microprocessors and Embedded Systems--Lecture 8 1 COMP3221: Microprocessors and Embedded Systems Lecture 8: Program Control Instructions
C Language Programming. C has gradually replaced assembly language in many embedded applications. Data types –C has five basic data types: void, char,
Programming the HC12 in C. Some Key Differences – Note that in C, the starting location of the program is defined when you compile the program, not in.
© 2010 Kettering University, All rights reserved..
CEG 320/520: Computer Organization and Assembly Language ProgrammingIntel Assembly 1 Intel IA-32 vs Motorola
ECE 448 FPGA and ASIC Design with VHDL Spring 2008.
ECE 448 FPGA and ASIC Design with VHDL
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
Objectives Implement pointers using indexed addressing modes Use pointers to access arrays, strings, structures, tables, and matrices Present finite-state.
ELN5622 Embedded Systems Class 2 Spring, 2003 Kent Orthner
ECE 265 – LECTURE 8 The M68HC11 Basic Instruction Set The remaining instructions 10/20/ ECE265.
ECE 449: Computer Design Lab Coordinator: Kris Gaj TAs: Tuesday session: Pawel Chodowiec Thursday session: Nghi Nguyen.
ECE 448 FPGA and ASIC Design with VHDL Spring 2010.
ECE Lecture 13 Motorola 68HC11. Resources 68HC11 E-series Reference Guide and if necessary 68HC11 E-series Technical Data 68HC11 Reference Manual.
Welcome to the ECE 449 Computer Design Lab Spring 2005.
George Mason University ECE 448 – FPGA and ASIC Design with VHDL ASICs vs. FPGAs ECE 448 Lecture 15.
ECE 447: Lecture 12 Logic, Arithmetic, Data Test and Control Instructions of MC68HC11.
6-1 EE 319K Introduction to Microcontrollers Lecture 6: Indexed Addressing Mode and Variants, Functional Debugging, Arrays, Strings.
ME4447/6405 The George W. Woodruff School of Mechanical Engineering ME4447/6405 Microprocessor Control of Manufacturing Systems and Introduction to Mechatronics.
George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction.
3-1 EE 319K Introduction to Microcontrollers Lecture 3: Addressing modes, Memory Operations, Subroutines, I/O, Logical/Shift Operations.
Machine Language ELEC 330 Digital Systems Engineering Dr. Ron Hayne.
1 ECE 372 – Microcontroller Design Assembly Programming HCS12 Assembly Programming Addressing Modes Stack Operations Subroutines.
8-1 EE 319K Introduction to Microcontrollers Lecture 8:Fixed Point Numbers, Local Variables, Binding, Allocation, Access, Deallocation.
Ch.2 Intro. To Assembly Language Programming
ECE Lecture 21 Typical Assembly Language Program Bugs.
Ch.2 Intro. To Assembly Language Programming From Introduction to Embedded Systems: Interfacing to the Freescale 9s12 by Valvano, published by CENGAGE.
George Mason University Follow-up Courses. ECE Department MS in Electrical Engineering MS EE MS in Computer Engineering MS CpE COMMUNICATIONS & NETWORKING.
Advanced Assembly Language Programming
ECE 447: Lecture 11 Introduction to Programming in Assembly Language.
ECE 448 FPGA and ASIC Design with VHDL Spring 2009.
1 Basic Processor Architecture. 2 Building Blocks of Processor Systems CPU.
Embedded Systems Lecture 5 January 25 th, 2016.
George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction.
1 Subroutines Advanced Programming. 2 Top-Down approach to problem solving Algorithm step by step description of how to solve a problem Divide and Conquer.
Revised: Aug 1, EE4390 Microprocessors Lessons 11, 12 Advanced Assembly Programming.
ELE22MIC Lecture 17 Writing 68HC11 software 68HC11 Main Timer System –Output Compare –What is different about TOC1?
1 The user’s view  A user is a person employing the computer to do useful work  Examples of useful work include spreadsheets word processing developing.
EE345 Chapter 2 Lecture 3 April Instruction and addressing modes 1.Extended Addressing 2.Direct Addressing 3.Inherent Addressing 4.Immediate Addressing.
Design methodology for Implementing a Microcontroller in a FPGA. Phillip Southard Ohio University EE 690 Reconfigurable Design.
5-1 EE 319K Introduction to Microcontrollers Lecture 5: Conditionals, Loops, Modular Programming, Sub- routines, Parameter passing.
ELE22MIC Lecture 18 Writing 68HC11 software 68HC11 Main Timer System
ECE 3430 – Intro to Microcomputer Systems
ECE 3430 – Intro to Microcomputer Systems
Addressing Modes in Microprocessors
ECE 3430 – Intro to Microcomputer Systems
Assembly Language Programming of 8085
ECE 3430 – Intro to Microcomputer Systems
ELE22MIC Lecture 18 Writing 68HC11 software 68HC11 Main Timer System
ECE 3430 – Intro to Microcomputer Systems
Wed. Sept 6 Announcements
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
ME4447/6405 Microprocessor Control of Manufacturing Systems and
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
ECE 447: Lecture 15 Stack Operations.
COMP3221: Microprocessors and Embedded Systems
Computer Systems An Introducton.
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
ECE511: Digital System & Microprocessor
An Introduction to the ARM CORTEX M0+ Instructions
Presentation transcript:

ECE 447: Lecture 16 Common Errors & Good Programming Style

Typical Assembly Language Program Bugs

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

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

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

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

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:

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

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

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 

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

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!

Good Programming Style

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

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)) ;

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

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’,’:’};

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

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)

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

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

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

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

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.

- 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:

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

Celoxica RC10 Educational Board

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