Download presentation
Presentation is loading. Please wait.
Published byLiliana Mason Modified over 9 years ago
2
Business Programming I Fall – 2000 By Jim Payne
3
Lecture 03Jim Payne - University of Tulsa2 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.
4
Lecture 03Jim Payne - University of Tulsa3 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.
5
Lecture 03Jim Payne - University of Tulsa4 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)
6
Lecture 03Jim Payne - University of Tulsa5 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,…
7
Lecture 03Jim Payne - University of Tulsa6 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
8
Lecture 03Jim Payne - University of Tulsa7 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 >= 60 COMPUTE COP = COP + 1 ELSE COMPUTE COF = COF + 1 ENDIF
9
Lecture 03Jim Payne - University of Tulsa8 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
10
Lecture 03Jim Payne - University of Tulsa9 New Instruction Set ACCEPTDISPLAYGOTO COMPUTEIF-ELSE-ENDIFDATA
11
Bertha Method IN Basket 70 80 100 40 10 999 Sum of Scores Counter of Scores Counter of Passing 000 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
12
Variable Naming SCR = Individual Score SOS = Sum of Scores COS = Counter of Scores COP = Counter of Passing AVG = Average Score = SOS / COS
13
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
14
Billy-O Program TOPINPSCR LDASCR ADC-999 BZAMID LDASOS ADDSCR STASOS LDACOS ADC1 STACOS LDASCR ADC-60 BNATOP LDACOP ADC1 STACOP BRUTOP MIDLDASOS DIVCOS STAAVG OUTAVG OUTCOS OUTCOP HLT SOSNUM0 COSNUM0 COPNUM0 END IN Basket 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
15
Flowchart IN Basket 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
16
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 Code 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
17
High-Level Language to Machine Code High-Level Language Assembler LanguageMachine Language Compilers – Interpreters - Translators LDA A MPY B STA C11011010010010001010101001 COMPUTE C = A * B
18
Lecture 03Jim Payne - University of Tulsa17
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.