Program Design

Download Report

Transcript Program Design

Program Design
• Divide and Conquer
– Divide the program into separate tasks
• Functional Decomposition
• Top-Down Design
– Divide an overall problem into discrete tasks,
each of which can be coded in a single
procedure!!!
Benefits of
Functional Decomposition
• Large problems may be more easily divided
into smaller tasks.
• A program is easier to maintain if each
procedure can be tested separately.
• A top-down design lets you see how
procedures are related to each other
• When the overall design is clear, it is easier
to concentrate on the details of each part
Example Program
• Write a program that will display the numbers of a
list
example:
given a list of 4 numbers (each having a
value between 0 and 9), display the
values, separated by a comma and a space.
1, 2, 3, 4
How do you go about doing this
• Divide and Conquer
Structure Chart for
Displaying a List of Numbers on the Screen
Display Number
(main)
Define the List
DB or BYTE Directive
Print Numbers in List to Screen
Int 21h, Function 2
Functional Decomposition of
Printing Numbers to screen
1. Point to beginning of list
2. Print character to screen
3. Move to next item in list
4. Check to see if end of list
5. If not, Return to Step 2
6. End Program
Functional Decomposition of
Printing Numbers to screen
1. Point to beginning of list
Use OFFSET operator to have BX point to address of first item
2. Print character to screen
Use Int 21h Function 2
(character must be stored in DL register)
3. Move to next item in list
INC BX
4. Check to see if end of list
IF Loop is being used, check value of CX
IF NO Loop, check for number of items
5. If not, Return to Step 2
6. End Program
Use Int 21h Function 4CH
Functional Decomposition of
Printing Numbers to screen
1. Point to beginning of list
mov bx, offset array
2. Print character to screen
mov ah, 2
mov dl, [bx]
int
21h
3. Move to next item in list
inc bx
4. Check to see if end of list
length of list must be put into CX before loop begins
Using Loop Instruction will cause loop to end when CX equals 0
5. If not zero, return to step 2
Set beginning of loop to step 2
6. End Program
mov ah, 4CH
Int 21h
Now combine blocks to write program
• Start with template
• Add instructions as needed to create
working program
• Add enough comments so that you can
reuse the code you write this week later
(and also so that at the end of the semester,
you can look at the code and quickly
determine what the code does!).