Business Programming I Fall – 2000 By Jim Payne Lecture 03Jim Payne - University of Tulsa2 A New...

17
Business Programming I Fall – 2000 By Jim Payne

Transcript of Business Programming I Fall – 2000 By Jim Payne Lecture 03Jim Payne - University of Tulsa2 A New...

Business Programming I

Fall – 2000By

Jim Payne

Lecture 03 Jim Payne - University of Tulsa 2

A New Programming Language

In our previous sessions, we have learned to develop assembler language program solutions for simple arithmetic problems.

Today, we will begin the process of developing a brand new programming language.

Lecture 03 Jim Payne - University of Tulsa 3

A New Programming Language

Goals for our new high-level language:

1) Combine several assembler instructions into one high-level instruction.

2) Allow for numeric and alphanumeric variables.

3) Begin to trust the internal operations of the computer.

4) Improve Input and Output flexibility.

Lecture 03 Jim Payne - University of Tulsa 4

Replace Line Labels with Line #’s

In Billy-O, we used line labels like TOP or MID so we could jump to a new label. (e.g BRU TOP)

Let’s replace those labels with line numbers on each statement and the branching instructions with GOTO instructions. (e.g. 200 GOTO 100)

Lecture 03 Jim Payne - University of Tulsa 5

Input/Output Statements

Let’s replace the INP statements of Billy-O with an ACCEPT statement and the OUT statements with DISPLAY statements.

General Form:

ACCEPT variable,variable,…DISPLAY variable,variable,…

Lecture 03 Jim Payne - University of Tulsa 6

COMPUTE statement

Let’s create a very powerful new statement called the COMPUTE statement. It can replace several assembler statements with one.

COMPUTE D = A + B * C

REPLACES: LDA B, MPY C, ADD A, STA D

Lecture 03 Jim Payne - University of Tulsa 7

Conditional Branching

Let’s make our If logic more user friendly. When we wanted to count those exam scores >= 60, we did things like ADC –60, BNA TOP, etc.

Let’s replace that with an IF or Decision structure.

IF SCR >= 60COMPUTE COP = COP + 1

ELSECOMPUTE COF = COF + 1

ENDIF

Lecture 03 Jim Payne - University of Tulsa 8

Variable Types

Up to now, we have used only numeric type variables. In the future, we will need variables for handling text inputs. For now, let’s just agree to put a $ after any variable name that might contain non-numeric information.

i.e. ACCEPT NAME$, AGE

DATA John Brown, 23

Lecture 03 Jim Payne - University of Tulsa 9

New Instruction Set

ACCEPT DISPLAY GOTO

COMPUTE IF-ELSE-ENDIF

DATA

Bertha Method

IN Baske

t

70

80

100

40

10

999

Sum of Scores

Counter of Scores

Counter of Passing

0 00

STEPS: (In Pseudocode Form)Pick up a card from the in basket.

If score = 999, do what? Else do what?

NOT EQUAL 999: Add score to Sum of Scores, Add 1 to Counter of Scores. If score >= 60, Add 1 to Counter of Passing. Then go read next score.

EQUAL 999: Compute Average Score = Sum of Scores / Counter of Scores. Print out report answers. Quit Processing

Variable Naming

SCR = Individual Score

SOS = Sum of Scores

COS = Counter of Scores

COP = Counter of Passing

AVG = Average Score = SOS / COS

Pseudocode

Input a value for SCR

If SCR = 999

Compute AVG = SOS / COS

Print Results and Quit

Else

Compute SOS = SOS + SCR

Compute COS = COS + 1

If SCR >= 60

Compute COP = COP + 1

EndIf

Endif

Go to Top of Program

Flowchart of Logic

Start

Stop

Billy-O ProgramTOP INP SCR

LDA SCR

ADC -999

BZA MID

LDA SOS

ADD SCR

STA SOS

LDA COS

ADC 1

STA COS

LDA SCR

ADC -60

BNA TOP

LDA COP

ADC 1

STA COP

BRU TOP

MID LDA SOS

DIV COS

STA AVG

OUT AVG

OUT COS

OUT COP

HLT

SOS NUM 0

COS NUM 0

COP NUM 0

END

IN Baske

t

70

80

100

40

10

999

New Program

100 ACCEPT SCR

110 IF SCR = 999

120 GOTO 220

130 ELSE

140 COMPUTE SOS = SOS + SCR

150 COMPUTE COS = COS + 1

160 IF SCR >= 60

170 COMPUTE COP = COP + 1

180 ELSE

190 ENDIF

200 GOTO 100

210 ENDIF

220 COMPUTE AVG = SOS / COS

230 DISPLAY AVG, COS, COP

240 END

Flowchart

IN Baske

t

70

80

100

40

10

999

New Program

100 ACCEPT SCR

110 IF SCR = 999

120 GOTO 220

130 ELSE

140 COMPUTE SOS = SOS + SCR

150 COMPUTE COS = COS + 1

160 IF SCR >= 60

170 COMPUTE COP = COP + 1

180 ELSE

190 ENDIF

200 GOTO 100

210 END-IF

220 COMPUTE AVG = SOS / COS

230 DISPLAY AVG, COS, COP

240 END

Start

Stop

Original Pseudocode

Input a value for SCR

If SCR = 999

Compute AVG = SOS / COS

Print Results and Quit

Else

Compute SOS = SOS + SCR

Compute COS = COS + 1

If SCR >= 60

Compute COP = COP + 1

EndIf

Endif

Go to Top of Program

New Program Code100 ACCEPT SCR

110 IF SCR = 999

120 GOTO 220

130 ELSE

140 COMPUTE SOS = SOS + SCR

150 COMPUTE COS = COS + 1

160 IF SCR >= 60

170 COMPUTE COP = COP + 1

180 ELSE

190 ENDIF

200 GOTO 100

210 END-IF

220 COMPUTE AVG = SOS / COS

230 DISPLAY AVG, COS, COP

240 END

High-Level Language to Machine Code

High-Level Language

Assembler Language

Machine Language

Compilers – Interpreters -Translators

LDA A MPY B STA C

11011010010010001010101001

COMPUTE C = A * B

Lecture 03 Jim Payne - University of Tulsa 17