DOC PREVIEW
UCSC CMPE 012 - Programming and programming structures

This preview shows page 1-2 out of 5 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 5 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 5 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 5 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

1Programming and programming structuresTextbook Chapter 6CMPE12 – Summer 2008CMPE12 – Summer 2008 – Slides by ADB 2What is a program? What is a program? Set of instructions written in a programming language that tells the computer what to doCMPE12 – Summer 2008 – Slides by ADB 3The programming process Defining the problem Planning the solution Describing the algorithm Pseudo-code Flow chart Coding the program Compiling and testing the program Documenting the programCMPE12 – Summer 2008 – Slides by ADB 4 What is the input What output do you expect How do you get from the input to the outputThe programming process: Defining the problemCMPE12 – Summer 2008 – Slides by ADB 5 Algorithm: detailed solutions to a given problem.  The algorithm must: Be unambiguous Always terminate in a finite number of instructions (Possibly!) solve the problemThe programming process: Planning the solutionCMPE12 – Summer 2008 – Slides by ADB 6Describing the algorithm: Pseudo-codeSumming all integers to 1001. Initialize counter to 12. Initialize summing variable to 03. Add counter to summing variable4. Is counter equal to 100 yet?2CMPE12 – Summer 2008 – Slides by ADB 7Has logic structure, but no language syntaxFrom: A. Di Blas, A, Jagota, and R. P. Hughey “A Range-Compaction Heuristic for Graph Coloring”Journal of Heuristics, v. 9, n. 6, Dec. 2003, pp. 489-506, Kluver Acad. Pub.Describing the algorithm: Pseudo-codeCMPE12 – Summer 2008 – Slides by ADB 8Describing the algorithm: Flow chartCMPE12 – Summer 2008 – Slides by ADB 9Describing the algorithm: Flow chartStartAddress envelopePlace letter in envelopeHave stamp?Borrow stampPlace stamp on envelopeStopProduce letterStart/stopConnectorProcessDecisionInput/outputCMPE12 – Summer 2008 – Slides by ADB 10 Translate algorithm into a formal programming language Within syntax of the language How to key in the statements? Text editor Programming environment  Interactive Development Environment (IDE)The programming process: Coding the programCMPE12 – Summer 2008 – Slides by ADB 11 Compiler Translates from source module into object module Finds syntax errors Linker Combines object modules with libraries to create load module Finds undefined external references Debugger Execute program in a controlled environment Run using data that tests all statements Finds logic errorsThe programming process: Compiling and testing the programCMPE12 – Summer 2008 – Slides by ADB 12 Much better when performed throughout the development! Material generated during each step Problem definitions Program plan Comments within source code Testing of procedures Narrative Layouts of input and output Program listingThe programming process: Documenting the program3CMPE12 – Summer 2008 – Slides by ADB 13 1stGeneration: Machine Level 2ndGeneration: Assembly Level 3rdGeneration: High-level (C, Fortran, Pascal, BASIC, COBOL, C++, Java) 4thGeneration: Application-specific (SQL, MATLAB) 5thGeneration: Declarative languages (Prolog, regex)Programming LanguagesCMPE12 – Summer 2008 – Slides by ADB 14FORTRAN FORTRAN = Formula Translator IBM custom language Developed between 1954 and 1966CMPE12 – Summer 2008 – Slides by ADB 15COBOL COBOL = Common Business-Oriented Language Defined in 1960CMPE12 – Summer 2008 – Slides by ADB 16BASIC BASIC = Beginners, All-purpose Symbolic Instruction Code Born in 1963CMPE12 – Summer 2008 – Slides by ADB 17C++ C++, or “C with classes” Born in 1983CMPE12 – Summer 2008 – Slides by ADB 18Programming constructsIterativeConditionalSequentialBlock ABlock BBlock A Block BcondTFBlock ABlock BcondTF4CMPE12 – Summer 2008 – Slides by ADB 19In LC-3LD R0, countBRpz endifADD R0, R0, #1endif ; next inst. goes hereIn Cif (count < 0)count = count + 1;IF-THEN-ELSECMPE12 – Summer 2008 – Slides by ADB 20IF-THEN-ELSELD R0, countBRpz endifADD R0, R0, #1endif:; next inst. goes hereif (count < 0)count = count + 1;In LC-3In CCMPE12 – Summer 2008 – Slides by ADB 21In Cwhile (count > 0) {a = a + count;count--;}In LC-3LD R1, aLD R0, countwhile BRnz endwhileADD R1, R1, R0ADD R0, R0, #-1BR whileendwhile ST R1, aST R0, countWHILE-DOCMPE12 – Summer 2008 – Slides by ADB 22WHILE-DOLD R1, aLD R0, countwhile: BRnz endwhileADD R1, R1, R0ADD R0, R0, #-1BR whileEndwhile: ST R1, aST R0, countwhile (count > 0) {a = a + count;count--;}In LC-3In CCMPE12 – Summer 2008 – Slides by ADB 23In Cdo {if (a < b)a++;if (a > b)a--;} while (a != b)In LC-3LD R0, aLD R1, bJSR Subrepeat BRpz secondifADD R0, R0, #1JSR Subsecondif BRnz untilADD R0, R0, #-1until JSR SubBRnp repeatDO-WHILECMPE12 – Summer 2008 – Slides by ADB 24DO-WHILELD R0, aLD R1, bJSR Subrepeat: BRpz secondifADD R0, R0, #1JSR Subsecondif: BRnz untilADD R0, R0, #-1until: JSR SubBRnp repeatdo {if (a < b)a++;if (a > b)a--;} while (a != b)In LC-3In C5CMPE12 – Summer 2008 – Slides by ADB 25In Cfor (i = 3; i <= 8; i++){ a = a + i;}In LC-3LD R0, aAND R1, R1, #0ADD R1, R1, #3for ADD R2, R1, #-8 BRp endforADD R0, R0, R1ADD R1, R1, #1BR forendforFORCMPE12 – Summer 2008 – Slides by ADB 26FORLD R0, aAND R1, R1, #0ADD R1, R1, #3for: ADD R2, R1, #-8 BRp endforADD R0, R0, R1ADD R1, R1, #1BR forendfor:for (i = 3; i <= 8; i++){ a = a + i;}In LC-3In CCMPE12 – Summer 2008 – Slides by ADB 27Recommended exercises Ex 6.4, 6.5, 6.7, 6.8 Ex 6.11 write the assembly code and simulate Ex 6.12 write code and simulate Ex 6.14, 6.15, 6.16, 6.17, 6.19, all really good inverse problems Ex 6.13 Ex 6.18 is good, but kind of


View Full Document

UCSC CMPE 012 - Programming and programming structures

Download Programming and programming structures
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Programming and programming structures and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Programming and programming structures 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?