ipc144 session 2 computer organization, problem analysis and program design

47
IPC144 Session 2 Computer Organization, Problem Analysis and Program Design 1

Upload: carr

Post on 24-Jan-2016

51 views

Category:

Documents


0 download

DESCRIPTION

IPC144 Session 2 Computer Organization, Problem Analysis and Program Design. 1. Objectives: By the end of this session, the student will be able to: List the first three stages of the evolution of computer languages Compare the three stages from a programmer's point of view - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: IPC144 Session 2 Computer Organization, Problem Analysis and Program Design

IPC144Session 2

Computer Organization, Problem Analysis and Program Design

1

Page 2: IPC144 Session 2 Computer Organization, Problem Analysis and Program Design

Objectives:By the end of this session, the student will be able to:List the first three stages of the evolution of computer languagesCompare the three stages from a programmer's point of viewList other 3GL languagesConstruct Boolean Logic ChartsApply Boolean Logic to problemsList the steps in a model Systems Development Life CycleDescribe the purpose of each of the model stepsList the 7 steps of a model Program Development CycleDescribe the purpose of each step of the PDCList the steps that occur when compiling a computer program

4

Page 3: IPC144 Session 2 Computer Organization, Problem Analysis and Program Design

Software

SoftwareSoftware is a set of instructions that cause the computer to perform specific tasks in a specific order, and make simple decisions about the data it encounters. The software must be written by people in order to be supplied to the computer. The software is written in a specialized language.

There have been many generations of computer languages:machine languageassembly languagehigh-level language (3GL)very high-level language (4GL)natural language

5

Page 4: IPC144 Session 2 Computer Organization, Problem Analysis and Program Design

Software, continued

Machine Language SoftwareThis software is in the language of the processor. This language is not easily readable by humans as it consists of numbers only.

The instructions will consist ofop-codes (operation codes) and,operands (sometimes)

Op-codesThe op-codes are fetched and decoded by the Control Unit, and executed by the ALU.

OperandsThe operands are either scalar data (a fixed number, such as 5) or a memory address where data is stored. These are also fetched by the Control Unit for use by the ALU.

6

Page 5: IPC144 Session 2 Computer Organization, Problem Analysis and Program Design

Software, Continued

Machine language for Motorola 6809 (8-bit CPU)

00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 124F 97 13 96 12 27 09 4A 97 12 96 13 9B 11 20 F1 3E 02 05

addressop-codeoperanddata

The above program multiplies two numbers by repeated addition.

i.e.: 5 x 2 = 2 + 2 + 2 + 2 + 2

7

Page 6: IPC144 Session 2 Computer Organization, Problem Analysis and Program Design

Software, Continued

Assembly languageThis is a small step forward. The numeric instructions from machine language have been replaced by mnemonics. This makes the programs must easier to read, however it still takes patience and a disciplined approach. There are some pockets of assembly programming that still exist.

The mnemonics are designed for each individual processor, however there are some mnemonics that you may see from processor to processor.

These mnemonics are not understood by the computer, so a simple program, called an Assembler, converts the mnemonics to numbers, and ultimately you end up with machine language.

The advantage of assembly is that the programs written are very compact and run very fast.

8

Page 7: IPC144 Session 2 Computer Organization, Problem Analysis and Program Design

Software, Continued

Assembly language for Motorola 6809 (8-bit CPU)0000 4F CLRA0001 97 13 :LOOP STA @130003 96 12 LDA @120005 27 09 BEQ :DONE0007 4A DECA0008 97 12 STA @12000A 96 13 LDA @13000C 9B 11 ADD @11000E 20 F1 BRA :LOOP000F 3E :DONE HLT0011 020012 050013

AddressMachine Language (output from assembler)Assembly Language (written by programmer)

9

Page 8: IPC144 Session 2 Computer Organization, Problem Analysis and Program Design

Software, continued

High-level languageThere are many high-level languages that exist. In these languages, the programmer is using something that almost passes as a human language. However, programs written in these languages must be converted to machine language.

The advantage to these languages is that there are relatively easy to learn, although you might not believe me when we start talking about C. The disadvantage is that the machine code that is generated is not as optimized as code written directly in machine language.

These languages are not specific to a particular processor- therefore they are easily transported from processor to processor.

10

Page 9: IPC144 Session 2 Computer Organization, Problem Analysis and Program Design

Software, continued

High-level language, continued

The assembly program in C How it would actually be written in Ci = 5; i = 5;j = 2; j = 2;k = 0; k = i * j;while (i > 0){ k = k + j; i--;}

11

Page 10: IPC144 Session 2 Computer Organization, Problem Analysis and Program Design

Software, continued

High-level language, continuedOther 3GL languages:

TAL (for Tandem computers)Turing (developed by University of Toronto, to teach well structured programming)COBOL (a language for business applications)FORTRAN (FORmula TRANslation - scientific and engineering applications)PASCAL (a simple well structured language)BASIC (a simple initially unstructured language for learning programming)

12

Page 11: IPC144 Session 2 Computer Organization, Problem Analysis and Program Design

13

Boolean Logic

Page 12: IPC144 Session 2 Computer Organization, Problem Analysis and Program Design

Boolean Logic

Boolean logicDeveloped by George Boole in the 19th century. A form of logical algebra, as opposed to mathematical algebra.

We are concerned with TRUE or FALSE values instead of numbers.

Sometimes the digits 1 and 0 or the letters T and F are used to represent the values of TRUE and FALSE respectively.

The algebra will consist of statements that can be evaluated to being either TRUE or FALSE:

'Today is Saturday' - FALSE'You are in a lecture' - TRUE'You are asleep in the lecture' - ??

14

Page 13: IPC144 Session 2 Computer Organization, Problem Analysis and Program Design

Boolean Logic, continued

Boolean logic, continuedThe expressions being evaluated will be mathematical expressions in this course:

5 = 6a > ba + 4 < c - 1

These expressions will evaluate to either TRUE or FALSE depending on the algebraic value of the variables.

a > b would be TRUE if 'a' was 5 and 'b' was 4.a > b would be FALSE if 'a' was 4 and 'b' was 5.

We can now take the results of the expressions and apply Boolean operators to them.

15

Page 14: IPC144 Session 2 Computer Organization, Problem Analysis and Program Design

Boolean Logic, continued

Truth TablesThe Boolean algebra is summarized in 'Truth Tables'. There are two sections to the Truth Table:ConditionsResult

ConditionsThere are 1 or more columns in the Conditions section, depending on the number of possible combinations of TRUE and FALSE being tested.1 column = 2 possible conditions2 columns = 4 possible conditions3 columns = 8 possible conditionsn columns = 2n possible conditions

ResultThe result column will contain only 1 possible outcome for each condition, the result will be either TRUE or FALSE.

16

Page 15: IPC144 Session 2 Computer Organization, Problem Analysis and Program Design

Boolean Logic, continued

Boolean NOT operatorThe Boolean NOT operator simply reverses the values of TRUE and FALSE. There is only one possible column in the conditions section:

Examples (assuming x is TRUE, y is FALSE):NOT x result is FALSENOT y result is TRUENOT (5 < 6) result is FALSE

17

Conditions Result

a NOT a

FALSE TRUE

TRUE FALSE

Page 16: IPC144 Session 2 Computer Organization, Problem Analysis and Program Design

Boolean Logic, continued

Boolean OR operatorThe Boolean OR (also known as Inclusive-OR) looks for any conditions that contains at least one TRUE value:

Examples (assuming x is TRUE, y is FALSE):x OR y result is TRUEy OR y result is FALSEx OR x result is TRUE(7 > 8) OR (1 < 2) result is TRUE 18

Conditions Result

a b a OR b

FALSE FALSE FALSE

FALSE TRUE TRUE

TRUE FALSE TRUE

TRUE TRUE TRUE

Page 17: IPC144 Session 2 Computer Organization, Problem Analysis and Program Design

Boolean Logic, continued

Boolean OR operator, continuedAn extended OR Truth Table

19

Conditions Result

a b c a OR b OR c

FALSE FALSE FALSE FALSE

FALSE FALSE TRUE TRUE

FALSE TRUE FALSE TRUE

FALSE TRUE TRUE TRUE

TRUE FALSE FALSE TRUE

TRUE FALSE TRUE TRUE

TRUE TRUE FALSE TRUE

TRUE TRUE TRUE TRUE

Page 18: IPC144 Session 2 Computer Organization, Problem Analysis and Program Design

Boolean Logic, continued

Boolean AND operatorThe Boolean AND looks for any conditions that contain all TRUE values:

Examples (assuming x is TRUE, y is FALSE):x AND y result is FALSEy AND y result is FALSEx AND x result is TRUE(7 > 8) AND (1 < 2) result is FALSE 20

Conditions Result

a b a AND b

FALSE FALSE FALSE

FALSE TRUE FALSE

TRUE FALSE FALSE

TRUE TRUE TRUE

Page 19: IPC144 Session 2 Computer Organization, Problem Analysis and Program Design

Boolean Logic, continued

Boolean AND operator, continuedAn extended AND Truth Table

21

Conditions Result

a b c a AND b AND c

FALSE FALSE FALSE FALSE

FALSE FALSE TRUE FALSE

FALSE TRUE FALSE FALSE

FALSE TRUE TRUE FALSE

TRUE FALSE FALSE FALSE

TRUE FALSE TRUE FALSE

TRUE TRUE FALSE FALSE

TRUE TRUE TRUE TRUE

Page 20: IPC144 Session 2 Computer Organization, Problem Analysis and Program Design

Boolean Logic, continued

Boolean Exclusive-OR operatorThe Boolean XOR looks for any conditions that contain an odd number of TRUE values:

Examples (assuming x is TRUE, y is FALSE):x XOR y result is TRUEy XOR y result is FALSEx XOR x result is FALSE(7 > 8) XOR (1 < 2) result is TRUE 22

Conditions Result

a b a XOR b

FALSE FALSE FALSE

FALSE TRUE TRUE

TRUE FALSE TRUE

TRUE TRUE FALSE

Page 21: IPC144 Session 2 Computer Organization, Problem Analysis and Program Design

Boolean Logic, continued

Boolean XOR operator, continuedAn extended XOR Truth Table

23

Conditions Result

a b c a XOR b XOR c

FALSE FALSE FALSE FALSE

FALSE FALSE TRUE TRUE

FALSE TRUE FALSE TRUE

FALSE TRUE TRUE FALSE

TRUE FALSE FALSE TRUE

TRUE FALSE TRUE FALSE

TRUE TRUE FALSE FALSE

TRUE TRUE TRUE TRUE

Page 22: IPC144 Session 2 Computer Organization, Problem Analysis and Program Design

Boolean Logic, continued

Order of PrecedenceJust as in mathematics, you have an order of precedence when calculating an expression. What is the result of:

5 + 22 x 2 / 4 + (7 + 6 x 7) - 2 x 7

In Boolean Algebra, the order of precedence, (unless overridden by brackets) is:perform NOT operations first,followed by AND operations,followed by XOR operations,followed by OR.

Just like multiplication is transitive in Mathematics, the Boolean AND, OR and XOR are transitive.a x b x c = c x b x a = b x a x c = c x a x b = b x c x a = a x c x ba & b & c = c & b & a = b & a & c = c & a & b = b & c & a = a & c & b

What is the Truth Table for: a AND b XOR c?a AND b XOR NOT c OR b?

24

Page 23: IPC144 Session 2 Computer Organization, Problem Analysis and Program Design

Boolean Logic, continued

Order of PrecedenceWhat is the Truth Table for: a AND b XOR c?

25

Conditions Result

a b c a AND b a AND b XOR c

FALSE FALSE FALSE FALSE FALSE

FALSE FALSE TRUE FALSE TRUE

FALSE TRUE FALSE FALSE FALSE

FALSE TRUE TRUE FALSE TRUE

TRUE FALSE FALSE FALSE FALSE

TRUE FALSE TRUE FALSE TRUE

TRUE TRUE FALSE TRUE TRUE

TRUE TRUE TRUE TRUE FALSE

Page 24: IPC144 Session 2 Computer Organization, Problem Analysis and Program Design

Boolean Logic, continued

Order of PrecedenceWhat is the Truth Table for: a AND b XOR NOT c OR b?

26

Conditions Result

a b c NOT c a AND b

FALSE FALSE FALSE TRUE FALSE TRUE TRUE

FALSE FALSE TRUE FALSE FALSE FALSE FALSE

FALSE TRUE FALSE TRUE FALSE TRUE TRUE

FALSE TRUE TRUE FALSE FALSE FALSE TRUE

TRUE FALSE FALSE TRUE FALSE TRUE TRUE

TRUE FALSE TRUE FALSE FALSE FALSE FALSE

TRUE TRUE FALSE TRUE TRUE FALSE TRUE

TRUE TRUE TRUE FALSE TRUE TRUE TRUE

a AND b XOR NOT c

a AND b XOR NOT c OR b

Page 25: IPC144 Session 2 Computer Organization, Problem Analysis and Program Design

Boolean Logic, continued

Exercises1) What is the Truth Table for: a AND NOT b OR NOT a AND b2) TRUE AND FALSE OR NOT FALSE

Assuming the variables X, Y and Z have been assigned the values 5, 7 and 12 respectively, what is the result (TRUE or FALSE) of the following expressions:3) X = 5 4) X < Y5) X + Y > Z6) (X > 5) OR (Y > 5)7) NOT (X = 5)8) (X + Y > Z) AND (Z < 24) OR NOT (Y < 3)9) Create an expression that will result in TRUE when any of the variables (A, B, C) are greater than 0. A, B, C can be any number, positive, negative, fractional.10) Create an expression that will result in FALSE only when all three variables (A, B, C) are equal to 0) A, B, C can be any number, positive, negative, fractional.

27

Page 26: IPC144 Session 2 Computer Organization, Problem Analysis and Program Design

Boolean Logic, continued

Exercises1) What is the Truth Table for: a AND NOT b OR NOT a AND b - see XOR table2) TRUE AND FALSE OR NOT FALSE - TRUE

Assuming the variables X, Y and Z have been assigned the values 5, 7 and 12 respectively, what is the result (TRUE or FALSE) of the following expressions:

3) X = 5 - TRUE4) X < Y - TRUE5) X + Y > Z - FALSE6) (X > 5) OR (Y > 5) - TRUE7) NOT (X = 5) - FALSE8) (X + Y > Z) AND (Z < 24) OR NOT (Y < 3) - TRUE9) Create an expression that will result in TRUE when any of the variables (A, B, C)

are greater than 0 - (A>0) OR (B>0) OR (C>0)10) Create an expression that will result in FALSE only when all three variables (A, B,

C) are equal to 0) - NOT (A=0) OR NOT(B=0) OR NOT (C=0)

28

Page 27: IPC144 Session 2 Computer Organization, Problem Analysis and Program Design

29

Systems Development Life Cycle

Page 28: IPC144 Session 2 Computer Organization, Problem Analysis and Program Design

Systems Development Life Cycle

BackgroundAs systems become more complex, and businesses become more reliant on computers, means to structure the way new software is delivered is needed. There are two aspects that will be discussed:

System Development Life CycleProgram Development Cycle

The Program Development Cycle is a subset of the System Development Life Cycle.

The following slides will provide an overview of SDLC and PDC. The section on PDC will be investigated closer for the remainder of the course.

30

Page 29: IPC144 Session 2 Computer Organization, Problem Analysis and Program Design

Systems Development Life Cycle

System Development Life CycleThe steps of the System Development Life Cycle are:

Analyse SystemDefine System RequirementsDesign New SystemDevelop New SystemAccept New SystemImplement System

These steps are guidelines, and are not cast in stone. Each company will have some variation of these steps. There may be more steps, or some steps will be combined.

31

Page 30: IPC144 Session 2 Computer Organization, Problem Analysis and Program Design

Systems Development Life Cycle

SDLC: Analyse System

Performed on existing manual systems as well as existing automated systemsPerformed by System AnalystMost effectively performed by interviewing the usersIdentify what is done, and howIdentify any problems with current systemGo-No Go Decision based on ROI estimates

32

Page 31: IPC144 Session 2 Computer Organization, Problem Analysis and Program Design

Systems Development Life Cycle

SDLC: Define System Requirements

What changes are requiredSystem Analyst works with Business AnalystDevelop 'look and feel' of new systemDetermine what needs to be done (not how)Every input, output and process is documented:

Output: reports, screen designs Input: what data, where does it come from Process: what activities are required to produce the output

Go-No Go Decision

33

Page 32: IPC144 Session 2 Computer Organization, Problem Analysis and Program Design

Systems Development Life Cycle

SDLC: Design New System

Define all programs, files, databases, manual processesSystem Flowcharts are a common toolLike a program flowchart

Major inputs Major outputs Inter-relationships between entities in system

No details as to how the programs work

34

Page 33: IPC144 Session 2 Computer Organization, Problem Analysis and Program Design

Systems Development Life Cycle

SDLC: Develop New System

Involves designing, coding and unit-testingUses Program Development CycleGoal is high-quality well structured programsMain focus of the remainder of this course

35

Page 34: IPC144 Session 2 Computer Organization, Problem Analysis and Program Design

Systems Development Life Cycle

SDLC: Accept New System

Performed by Business user or Representative who has intimate knowledge of Business functionality of the systemEntire system is tested to ensure it conforms to the System Requirements (Phase 2)Assumes no knowledge of internal workings of systemSystem documentation reviewedImplementation strategies discussedUsers trained

36

Page 35: IPC144 Session 2 Computer Organization, Problem Analysis and Program Design

Systems Development Life Cycle

SDLC: Implement New System

When the new system is implemented into the production environmentEvaluation of new system (comparison between the expected objectives and the actual results)Results of the evaluation may become the input to a subsequent SDLC

37

Page 36: IPC144 Session 2 Computer Organization, Problem Analysis and Program Design

38

Program Development Cycle

Page 37: IPC144 Session 2 Computer Organization, Problem Analysis and Program Design

Program Development Cycle

Program Development CycleThe steps of the Program Development Cycle are:

Define the ProblemOutline the SolutionDevelop the Solution into an AlgorithmTest the Algorithm for CorrectnessCode the Program into a Specific Language (C)Run the Program on the ComputerDocument and Maintain the Program

These steps are guidelines, and are not cast in stone. Each company will have some variation of these steps. There may be more steps, or some steps will be combined.

39

Page 38: IPC144 Session 2 Computer Organization, Problem Analysis and Program Design

Program Development Cycle

PDC: Define the Problem

Must have a clear understanding of the problemThere is no room for assumptionsThere is no difference between solving the wrong problem correctly and solving the right problem incorrectlyTo help with analysis, the problem should be broken into:

Inputs Outputs Processes

IPO Charts are a tool used

40

Page 39: IPC144 Session 2 Computer Organization, Problem Analysis and Program Design

Program Development Cycle

PDC: Outline the Solution

Break problem into smaller tasks or stepsCreate a rough draft of the solution, may include

Major processing steps Major sub-tasks (if any) Major control structures (repetition loops) Major variables and record structures Mainline logic of the program

Top-down designModularity and Hierarchy charts are tools used

41

Page 40: IPC144 Session 2 Computer Organization, Problem Analysis and Program Design

Program Development Cycle

PDC: Develop the Outline into an Algorithm

Computers cannot devise a plan or decide to actComputers can only do what they are told, exactly the way they are toldComputers do what you tell them to do, not what you want them to doAn algorithm is a set of precise instructions which describe the task to be performed and the order in which they are to be carried outFlowcharts and Pseudocode are tools to be discussed

42

Page 41: IPC144 Session 2 Computer Organization, Problem Analysis and Program Design

Program Development Cycle

PDC: Test the Algorithm for Correctness

One of the most important stepsIdentifies major logic errorsWalkthroughs are a technique for testingTest plans are used to document and plan the tests necessary to prove your algorithm performs as required

43

Page 42: IPC144 Session 2 Computer Organization, Problem Analysis and Program Design

Program Development Cycle

PDC: Code the Program

Performed only after previous design considerations have been completeIn this course the C language will be used, although these techniques can be used for any language (Fortran, COBOL, BASIC, Pascal, Turing, TAL...)Unfortunately, this is where many people begin PDC or SDLC

44

Page 43: IPC144 Session 2 Computer Organization, Problem Analysis and Program Design

Program Development Cycle

PDC: Run the Program

Most will find this the most rewarding stepThis step involves the compiler, which will identify syntax errors and some basic coding/logic errorsFurther testing takes place against a Test PlanCan be very frustrating if the design and testing is incomplete before the coding is performedMay need to be performed several times

45

Page 44: IPC144 Session 2 Computer Organization, Problem Analysis and Program Design

Program Development Cycle

PDC: Document and Maintain Program

Documentation is an ongoing task throughout the PDCExternal DocumentationInternal DocumentationMaintenance takes place during the life of the program, due to:Enhancements (new functionality, new requirements)Bugs

46

Page 45: IPC144 Session 2 Computer Organization, Problem Analysis and Program Design

47

Compile Process

Page 46: IPC144 Session 2 Computer Organization, Problem Analysis and Program Design

Compile Process

Compile Process

As mentioned, a high-level language must be converted to machine language. This process is referred to as compiling the program. The program is a file that contains instructions written in the high-level language. It is used as data to the compiler, which generates machine language.

48

Page 47: IPC144 Session 2 Computer Organization, Problem Analysis and Program Design

Compile Process

Compile ProcessThe compile process starts by taking the source file (the file containing the high-level instructions) and converts it into an object file. The object file contains some machine language and some points that additional code needs to be attached to.

The object file is linked into the operating system, and the final result is an executable file containing the machine language instructions ready to run.

49

Source file(3GL LanguageText File)

Library files (for O/S)

Executable file

Translator LinkerObject File

Compiler