Transcript 330_04

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
2
Program Design
 Programmers' Goals





 Market Conditions
Write the shortest
program
Write the fastest
program
Write an easily
understood program
Write and easily
modified program
Meet the schedule




330_04
Microprocessor speed
increases
Chip cost reductions
Memory size increases
Secondary storage
evolution
3
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
4
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
5
Flowchart Symbols
Action
Symbol
Begin / End
Process
Decision
Connector
330_04
6
Example Flowchart
330_04
7
Structured Programming
 Fundamental Program Structures



SEQUENCE
IF-THEN-ELSE
DO-WHILE
 Extended Program Structures


DO-UNTIL
IN-CASE-OF
330_04
8
SEQUENCE Structure
330_04
9
IF-THEN-ELSE Structure
330_04
10
IF-THEN-ELSE Example
Pressure
over limit?
Set warning
to false
Set warning
to true
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

330_04 LAST
11
DO-WHILE Structure
330_04
12
DO-WHILE Example
* 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

Initialize
nonzero count
Initialize
table pointer
Table entry Yes
zero?
No
Increment
nonzero count
Advance
pointer
330_04
13
DO-UNTIL Structure
330_04
14
IN-CASE-OF Structure
330_04
15
Top Down Design
Start
Module 1
Module 1
Module 2
Task 1
Task 2
Module 2
Task 3
End 1
End
End 2
330_04
16
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
17
Top/Down Assembly Language
Start
Module 1
Module 2
End
**************************
** Program Name
** Description
**************************
** Data Section
**************************
ORG
$10
DATA1
RMB
2
Comment
*
**************************
** Program Section
**************************
ORG
$E010
330_04
18
Top/Down Assembly Language
Module 1
Task 1
Task 2
End 1
*------------------------* Module 1
*------------------------* Task 1
*
Subtask 1a
START
LDD
#0000
STD
DATA1
*
Subtask 1b
LDAA DATA2
* Task 2

*-------------------------
330_04
19
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
20
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
21
Summary




Program Design
Flowcharts
Structured Programming
Top/Down Design
330_04
22