230 likes | 405 Views
Program Structure and Design. ELEC 330 Digital Systems Engineering Dr. Ron Hayne. Software Facts. Software Cost Expensive to develop Volume reduces unit cost Software (and documentation) Quality Often poor Inadequate testing (debugging) Programming Difficult Tedious.
E N D
Program Structure and Design ELEC 330 Digital Systems Engineering Dr. Ron Hayne
Software Facts • Software Cost • Expensive to develop • Volume reduces unit cost • Software (and documentation) Quality • Often poor • Inadequate testing (debugging) • Programming • Difficult • Tedious 330_04
Programmers' Goals Write the shortest program Write the fastest program Write an easily understood program Write and easily modified program Meet the schedule Market Conditions Microprocessor speed increases Chip cost reductions Memory size increases Secondary storage evolution Program Design 330_04
Goals vs. Reality • Write the shortest program • Tricks usually lead to problems • Write the fastest program • Profile and optimize parts that make a difference • Write an easily understood program • Simple straightforward problem solutions • Write an easily modified program • Modifications happen frequently • Meet the schedule • Good software delivered late is often not profitable 330_04
Practical Programming • Don't use a single resource for multiple purposes • Use no intimate knowledge of hardware configuration • Keep the instructions and data separated • Use tables to collect program parameters and data • Only put constant data within instructions • Avoid tricks • Clever use of instructions not easy to alter • Don't write self-modifying programs • Use the instructions in the instruction set well 330_04
Flowchart Symbols 330_04
Example Flowchart 330_04
Structured Programming • Fundamental Program Structures • SEQUENCE • IF-THEN-ELSE • DO-WHILE • Extended Program Structures • DO-UNTIL • IN-CASE-OF 330_04
SEQUENCE Structure 330_04
IF-THEN-ELSE Structure 330_04
PRESS RMB 1 WARNING RMB 1 LIMIT FCB 100 * PRESSURE OVER LIMIT? START LDAA PRESS CMPA LIMIT BHI OVER YES * SET WARNING TO FALSE CLR WARNING BRA LAST * SET WARNING TO TRUE OVER LDAA #$01 STAA WARNING LAST IF-THEN-ELSE Example Pressureover limit? Set warning to false Set warning to true 330_04
DO-WHILE Structure 330_04
* INITIALIZE NONZERO COUNT START CLR COUNT * INITIALIZE TABLE POINTER LDX #TABLE * TABLE ENTRY ZERO? AGAIN TST 0,X BEQ LAST YES * INCREMENT NONZERO COUNT INC COUNT * ADVANCE POINTER INX BRA AGAIN LAST DO-WHILE Example Initializenonzero count Initializetable pointer Table entryzero? Yes No Incrementnonzero count Advancepointer 330_04
DO-UNTIL Structure 330_04
IN-CASE-OF Structure 330_04
Start Module 1 Module 1 Module 2 Task 1 Task 2 Module 2 End 1 Task 3 End End 2 Top Down Design 330_04
Top/Down Design • Develop flow charts in order, top first • Start coding after all levels are developed • Run program modules as soon as practical • Use structured programming in each module • Comment as you code, in accordance with flowcharts • Include program structure info in your comments • Keep flowchart symbols at functional level • Keep flowcharts independent of hardware • No more than ten symbols per flowchart • Make flowcharts conform to structured programming 330_04
************************** ** Program Name ** Description ************************** ** Data Section ************************** ORG $10 DATA1 RMB 2 Comment * ************************** ** Program Section ************************** ORG $E010 Start Module 1 Module 2 End Top/Down Assembly Language 330_04
*------------------------- * Module 1 *------------------------- * Task 1 * Subtask 1a START LDD #0000 STD DATA1 * Subtask 1b LDAA DATA2 * Task 2 *------------------------- Module 1 Task 1 Task 2 End 1 Top/Down Assembly Language 330_04
Top/Down Design Teams • Teams of people write most programs • Flowcharts and written materials document design • Interaction between program modules very important • Team members work on different modules • Structured programming necessary to ensure modules will fit together 330_04
Top/Down Implementation • Start writing and running the program soon after starting the design • Start writing the program even before designing the lower levels • Dummy modules called stubs • Program Testing • Running and demonstrating the program containing stubs checks the design, overall function and initial coding • Stubs replaced by actual modules as they are developed 330_04
Summary • Program Design • Flowcharts • Structured Programming • Top/Down Design 330_04