Program Structure and Design

Preview:

DESCRIPTION

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. - PowerPoint PPT Presentation

Citation preview

Program Structure and Design

ELEC 330

Digital Systems Engineering

Dr. Ron Hayne

330_04 2

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 3

Program Design

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

330_04 4

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 5

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 6

Action Symbol

Begin / End

Process

Decision

Connector

Flowchart Symbols

330_04 7

Example Flowchart

330_04 8

Structured Programming

Fundamental Program Structures SEQUENCE IF-THEN-ELSE DO-WHILE

Extended Program Structures DO-UNTIL IN-CASE-OF

330_04 9

SEQUENCE Structure

330_04 10

IF-THEN-ELSE Structure

330_04 11

IF-THEN-ELSE ExamplePRESS 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

Set warning to false

Pressureover limit?

Set warning to true

330_04 12

DO-WHILE Structure

330_04 13

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

Table entryzero?

Incrementnonzero count

Initializenonzero count

Initializetable pointer

Advancepointer

No

Yes

330_04 14

DO-UNTIL Structure

330_04 15

IN-CASE-OF Structure

330_04 16

Top Down Design

Module 2

Start

End

Module 1

Task 2

Module 1

End 1

Task 1

Task 3

Module 2

End 2

330_04 17

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 18

Top/Down Assembly Language

**************************

** Program Name

** Description

**************************

** Data Section

**************************

ORG $10

DATA1 RMB 2 Comment

*

**************************

** Program Section

**************************

ORG $E010

Module 2

Start

End

Module 1

330_04 19

Top/Down Assembly Language

*-------------------------

* Module 1

*-------------------------

* Task 1

* Subtask 1a

START LDD #0000

STD DATA1

* Subtask 1b

LDAA DATA2

* Task 2

*-------------------------

Task 2

Module 1

End 1

Task 1

330_04 20

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 21

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 22

Summary

Program Design Flowcharts Structured Programming Top/Down Design

Recommended