22
Program Structure and Design ELEC 330 Digital Systems Engineering Dr. Ron Hayne

Program Structure and Design

  • Upload
    iolana

  • View
    44

  • Download
    0

Embed Size (px)

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

Page 1: Program Structure and Design

Program Structure and Design

ELEC 330

Digital Systems Engineering

Dr. Ron Hayne

Page 2: Program Structure and Design

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

Page 3: Program Structure and Design

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

Page 4: Program Structure and Design

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

Page 5: Program Structure and Design

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

Page 6: Program Structure and Design

330_04 6

Action Symbol

Begin / End

Process

Decision

Connector

Flowchart Symbols

Page 7: Program Structure and Design

330_04 7

Example Flowchart

Page 8: Program Structure and Design

330_04 8

Structured Programming

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

Extended Program Structures DO-UNTIL IN-CASE-OF

Page 9: Program Structure and Design

330_04 9

SEQUENCE Structure

Page 10: Program Structure and Design

330_04 10

IF-THEN-ELSE Structure

Page 11: Program Structure and Design

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

Page 12: Program Structure and Design

330_04 12

DO-WHILE Structure

Page 13: Program Structure and Design

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

Page 14: Program Structure and Design

330_04 14

DO-UNTIL Structure

Page 15: Program Structure and Design

330_04 15

IN-CASE-OF Structure

Page 16: Program Structure and Design

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

Page 17: Program Structure and Design

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

Page 18: Program Structure and Design

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

Page 19: Program Structure and Design

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

Page 20: Program Structure and Design

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

Page 21: Program Structure and Design

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

Page 22: Program Structure and Design

330_04 22

Summary

Program Design Flowcharts Structured Programming Top/Down Design