Title: Business Programming I
1Business Programming I
2A 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.
3A 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.
4Replace 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) - Lets replace those labels with line numbers
on each statement and the branching instructions
with GOTO instructions. (e.g. 200 GOTO 100)
5Input/Output Statements
- Lets 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,
6COMPUTE statement
- Lets 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
7Conditional Branching
- Lets make our If logic more user friendly.
When we wanted to count those exam scores gt 60,
we did things like ADC 60, BNA TOP, etc. - Lets replace that with an IF or Decision
structure. - IF SCR gt 60
- COMPUTE COP COP 1
- ELSE
- COMPUTE COF COF 1
- ENDIF
8Variable Types
Up to now, we have used only numeric type
variables. In the future, we will need variables
for handling text inputs. For now, lets just
agree to put a after any variable name that
might contain non-numeric information. i.e.
ACCEPT NAME, AGE DATA John Brown, 23
9New Instruction Set
10Bertha Method
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 gt
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
11Variable Naming
SCR Individual Score SOS Sum of Scores COS
Counter of Scores COP Counter of Passing AVG
Average Score SOS / COS
12Pseudocode
Flowchart of Logic
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 gt 60
Compute COP COP 1 EndIf Endif Go to
Top of Program
13Billy-O Program
New Program
TOP 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 T
OP MID LDA SOS DIV COS STA AVG OUT AVG OUT COS
OUT COP HLT
SOS NUM 0 COS NUM 0 COP NUM 0 END
- ACCEPT SCR
- 110 IF SCR 999
- 120 GOTO 220
- 130 ELSE
- 140 COMPUTE SOS SOS SCR
- COMPUTE COS COS 1
- 160 IF SCR gt 60
- COMPUTE COP COP 1
- 180 ELSE
- 190 ENDIF
- GOTO 100
- 210 ENDIF
- COMPUTE AVG SOS / COS
- 230 DISPLAY AVG, COS, COP
- 240 END
-
14Flowchart
New Program
- ACCEPT SCR
- 110 IF SCR 999
- 120 GOTO 220
- 130 ELSE
- 140 COMPUTE SOS SOS SCR
- COMPUTE COS COS 1
- 160 IF SCR gt 60
- COMPUTE COP COP 1
- 180 ELSE
- 190 ENDIF
- GOTO 100
- 210 END-IF
- COMPUTE AVG SOS / COS
- 230 DISPLAY AVG, COS, COP
- 240 END
-
15Original Pseudocode
New Program Code
- ACCEPT SCR
- 110 IF SCR 999
- 120 GOTO 220
- 130 ELSE
- 140 COMPUTE SOS SOS SCR
- COMPUTE COS COS 1
- 160 IF SCR gt 60
- COMPUTE COP COP 1
- 180 ELSE
- 190 ENDIF
- GOTO 100
- 210 END-IF
- COMPUTE AVG SOS / COS
- 230 DISPLAY AVG, COS, COP
- 240 END
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 gt 60
Compute COP COP 1 EndIf Endif Go to
Top of Program
16High-Level Language to Machine Code
COMPUTE C A B
High-Level Language
Compilers Interpreters -Translators
LDA A MPY B STA C
11011010010010001010101001
Assembler Language
Machine Language
17Go TU !!!