1 / 93

Overview of Programming

Overview of Programming. Lecture 1. Software. Software are programs written to perform specific tasks Application programs perform a specific task for the user These programs include word processors, spreadsheets, and games (e.g. Microsoft Office, Matlab, etc.)

lucius
Download Presentation

Overview of Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Overview of Programming Lecture 1

  2. Software • Software are programs written to perform specific tasks • Application programs perform a specific task for the user • These programs include word processors, spreadsheets, and games (e.g. Microsoft Office, Matlab, etc.) • System programs take control of the computer, such as an operating system (e.g., Linux, Windows XP, etc.) • Programs that support the execution and development of other programs • Operating systems  execute other programs • Translation systems  development of other programs

  3. Application Software • Application software is the software that has made using computers indispensable and popular • Common application software • Word processors • Desktop publishing programs • Spreadsheets • Presentation managers • Drawing programs • Learning how to develop application software is our focus

  4. Operating System • Examples • Windows®, UNIX®, Mac OS X® • Controls and manages the computing resources • Important services that an operating system provides • File system • Directories, folders, files • Commands that allow for manipulation of the file system • Sort, delete, copy • Ability to perform input and output on a variety of devices • Management of the running systems

  5. SKIP: Aside on DOS… • Microsoft bought QDOS from Tim Paterson • QDOS was a “clone” (read: copy) of Gary Kildall’s CP/M (some of the original code is actually in there, comments and all) • Kildall later developed DR-DOS under the banner of his company, Digital Research • Bill Gates persuaded IBM to let his company retain marketing rights for DOS (renamed MS-DOS to differentiate from the PC-DOS they sold to IBM)

  6. Translation System • Set of programs used to develop software (i.e., other programs!) • A key component of a translation system is a translator • Some types of translators • Interpreter • Converts from one language to another one line at a time • Compiler • Converts from one language to another all in one shot • Linker • Combines resources • Examples • Microsoft Visual C++®, C++Builder®, g++, Code Warrior® • Performs compilation, linking, and other activities for different computer architectures…

  7. Computer Organization Basics

  8. Hardware Components of a Computer

  9. CPU (Central Processing Unit) • Control Unit • Fetches and decodes instructions • Controls flow of information in and out of MM • Controls operation of internal CPU components • Program Counter – points to next instruction to be executed • Instruction Register – holds instruction currently being executed • Arithmetic Logic Unit (ALU) – carries out all arithmetic and logical operations • Accumulator – holds results of ALU operation

  10. Central Processing Unit • Brains of the computer  Executes program instructions! • Arithmetic/Logic Unit performs arithmetic operations, and makes logical comparisons • Control Unit decodes and executes your instructions • Arithmetic operations are performed using the binary number system • Computer only understands 1’s and 0’s!

  11. The Control Unit • The fetch/execute cycle is the series of steps the CPU takes to execute an instruction • Performing the action specified by an instruction is known as executing the instruction • The program counter (PC) holds the memory address of the next instruction

  12. Secondary Storage • Secondary storage - the device that stores information permanently • Examples of secondary storage • hard disks • floppy disks • Memory sticks • CD-ROMs • tapes

  13. Input/Output Devices • Input devices feed data and programs into computers. They include: • keyboard • mouse • scanner • optical pen • secondary storage • Output devices display results. They include: • monitor • printer • secondary storage

  14. Main Memory • Directly connected to the CPU • When the power of the computer is turned off, everything in the main memory is lost – VOLATILE • All programs must be loaded into main memory before they can be executed • All data must be brought into main memory before it can be manipulated • Main Memory is different from the registers WITHIN the CPU which must eventually also get the data and instructions

  15. Main Memory Layout memory contents addresses

  16. Memory Units • Memory is an ordered sequence of storage cells, each capable of holding a piece of information • Each memory cell has its own unique address • The information held in a memory cell can be input data, computed values, or your program instructions. • Von Neumann Architecture!

  17. Memory Organization • Two circuit states correspond to 0 and 1 • bit (short for binary digit) • refers to a single 0 or 1 • nybble (4), byte (8), word (16 or 32 or 64), double word (32 or 64 or 128), etc. • Bit patterns represent both the computer instructions and computer data • Von Neumann architecture • 1 byte = 8 bits • 1 KB = 1024 bytes • 1 MB = 1024 x 1024 bytes = 1,048,576 bytes

  18. How Many Digits? • binary (base 2) numbers use 2 digits: JUST 0 and 1 • decimal(base 10) numbers use 10 digits: 0 THROUGH 9 • hexadecimal(base 16) numbers use 16 digits: 0 THROUGH 9 AND a THROUGH f

  19. Language of a Computer • The only language a computer directly understands is sequences of 0s and 1s • The language made up of 0s and 1s is called machine language • The digits 0 or 1 are called binary digits (bits) with eight bits equalling a byte • A sequence of 0s and 1s is also referred to as binary code • Each dialect of machine language is specific to a particular computer architecture (i.e., type of computer) • This means that machine language programs are NOT portable across different computer architectures

  20. Coding Schemes – Representing Human Language Characters • ASCII (American Standard Code for Information Interchange) • 128 characters • A is encoded as 1000001 (66th character) • 3 is encoded as 0110011 • EBCDIC • used by IBM • 256 characters • 8 bits • Unicode • 65536 characters • two bytes are needed to store a character

  21. Early Programming Languages… • Memory locations were referenced by their address • This made the process of giving a computer instructions to do things very cumbersome • E.g., storing the values 45 and 12 in memory locations 1652 and 2548 required instructions such as: • Get storage for two integers • Put 45 in location 1652 • Put 12 in location 2548 • Adding two numbers was even more cumbersome! • Add the contents of location 1652 to the contents of location 2548 and store the result into location 3000

  22. Programming Language Evolution • Early computers were programmed in machine language • Machine language is also called binary code • To calculate wages = rate * hours in machine language, the following sequence of instructions might be needed:

  23. Assembly Language • An instruction in assembly language is an easy-to-remember form called a mnemonic • An assembler is a program that translates a program in assembly language into machine language • E.g., compare instructions in Assembly and Machine languages:

  24. Higher Level Languages… • In high-level languages, symbolic names replace actual memory addresses • I.e., we give mnemonic names to memory addresses in addition to instructions! • The symbolic names for the memory locations where values are stored are called variables • A variable is a name given by the programmer to refer to a computer memory storage location • The word variable (just like variables in mathematics) is used because the value stored in the variable (or memory location) can change or vary • For each variable name that the programmer uses, the computer keeps track of the actual memory address corresponding to that variable • If memory addresses are analogous to the street addresses of houses, then naming a variable is equivalent to naming a house • E.g., referring to 1600 Pennsylvania Avenue as The White House

  25. Assembly Program Example Using assembly language instructions, the equation wages = rate * hours can be written as follows: LOAD rate MULT hours STOR wages

  26. First Generation Computer Programming Languages • Machine languages • 1’s and 0’s represent instructions and procedures (the Instruction Set) • Machine-dependent code (machine code) • Programmers have to know the structure of the machine (architecture), addresses of memory registers, etc. • Different for each hardware manufacturer (e.g., Intel differs from Motorola)

  27. Second Generation • Assembly language • Still “low-level” (i.e., machine architecture dependent) • But uses mnemonic command names • ADD(3,2), COMPARE(A,B), etc. • An “assembler” translates program source code into the appropriate machine language (binary code)  adds overhead

  28. First Generation vs. Second Generation Machine language Assembly 01001100 mov bx, offset value 11101001 mov ax, [bx] 10101010 add ax, 5 10001100 sub ax, 2 00001100 inc ax

  29. Third Generation • Largely Procedural languages (Imperative) • Not CPU dependent • High level • Command names are not about the machine any more • A=5 • B=A+6 • PRINT B • Command vocabulary and syntax rules • Compilerstranslate program source code into object code (machine language binary code) • Interpreters execute one line at a time  more overhead

  30. Cf. 2nd & 3rd Generation Assembly High level mov bx, offset value x=2; mov ax, [bx] if (x <= y) add ax, 5 x = x + 1; sub ax, 2 else inc ax x = x – 1;

  31. High-Level Languages • High-level languages are portable across different machine types (architectures) • The user writes high-level language programs in a language similar to natural languages (like English, e.g.) • The equationwages = rate * hourscan be written in C++ as wages = rate * hours • Most high-level languages are standardized by ISO/ANSI to provide an official description of the language • High-level languages include BASIC, FORTRAN, COBOL, Pascal, C++, C • A compiler is a program that translates a program written in a high-level language into machine language (binary code) for that particular machine architecture

  32. myprog.cpp myprog.obj myprog.exe SOURCE OBJECT EXECUTABLE written in C++ written in machine language written in machine language via compiler via linker other code from libraries, etc. (also in machine language) Three Fundamental C++ Program Stages

  33. Programming is really Problem Solving • Programming is a process of problem solving • Problem solving techniques • Analyze the problem • Outline the problem requirements • Specify what the solution should do • Design steps, called an algorithm, to solve the problem (the general solution) • Verify that your solution really solves the problem • Algorithm – a step-by-step problem-solving process in which a solution is arrived at in a finite amount of time

  34. Algorithms • Algorithm: the step-by-step sequence of instructions that describe how the data is to be processed to produce the desired output • Programming = the translation of the selected algorithm into a language the computer can use • Before actually programming (coding), you’ll express the algorithm using a flowchart, pseudocode, or formula

  35. Processing a program • To execute a program written in a high-level language such C++ • Use an editor to create a source program (code) in C++ • A source program (code) is a program written in a high-level language • Use the compiler to check that the program obeys the rules and translates the program in to an equivalent machine language object program • An object program is the machine language (binary code) version of the high-level language program that the CPU can understand and execute

  36. Processing a program (graphic) source program object program CPU scheules (and executes) programs in main memory executable code other object programs Loads executable program into main memory

  37. Problem Solving Process (Programming Life Cycle) • Step 1 - Analyze the problem • Outline the problem and its solution requirements • Design steps (algorithm) to solve the problem • Step 2 - Implement the algorithm • Implement the algorithm in a programming language • Verify that the algorithm works • Step 3 - Maintenance • Maintenance requires using and modifying the program if the problem domain changes ~75 % of costs!

  38. Problem Analysis: Coding-Execution Cycle

  39. Problem Solution and Software Development: Phase III. Maintenance • Maintenance includes • Ongoing correction of newly discovered bugs • Revisions to meet changing user needs • Addition of new features • Maintenance is usually the longest phase, and may be the primary source of revenue • Good documentation is vital for effective maintenance Also ~75 % of costs!

  40. Analyze the Problem • In order to minimize maintenance costs, you have to thoroughly understand what the problem is about • Understand the problem requirements • Does the program require interaction with the user? • Does the program manipulate data? • Is there any output of the program? • If the problem is complex, divide the problem into subproblems. • Analyze each subproblem as above

  41. Procedural Programming… • Structured design – dividing a problem into smaller subproblems • The process of implementing a structured design is called structured programming • Structured programming: • Each sub-problem is addressed by using three main control structures: sequence, selection, repetition • Leads to organized, well-structured computer programs (code) • Also allows for modular programming • The problem is divided into smaller problems in modular programming • Each subproblem is then analyzed independently • A solution is obtained to solve the subproblem • The solutions of all subproblems are then combined to solve the overall problem • Procedural programming is combining structured programming with modular programming

  42. Modular, Structured Programming • For example, solving Ax= b • 1st step: entering A, b • 2nd step: finding B=A-1 • 3rd step: multiple Bb • Each of the steps can be programmed as a subroutine • The finding of the inverse in Step 2 may have already been written and provided in the library

  43. Coding-Execution Cycle • Remove compilation and semantic (logic) errors (debugging) • Link object code with system resources (predefined subroutineslike finding A-1) • Compiler onlyguarantees that the program follows the rules of the language, but it does not guarantee that it will run correctly ! • So, test the results with sample data to see if the program is calculating what you intend to calculate before testing it on real data • If results are inconsistent, go back to debugging

  44. Object-Oriented Design • Identify components called objects • Specify relevant data and possible operations to be performed on that data • Each object consists of data and operations on that data • An object combines data and operations on the data into a single unit – a class is a blueprint for objects • A programming language that implements OOD is called an object-oriented programming (OOP) language Just like a recipe (class) combines the ingredients (data) with the instructions (operations) for mixing those ingredients

  45. How to do Object-Oriented Programming • Learn how to represent data in computer memory, how to manipulate data, and how to implement operations • Write algorithms and implement them in a programming language • Learn how to combine data and operations on the data into a single unit • C++ was designed especially to implement OOD • OOD works well and is used in conjunction with structured design

  46. Software Development Activities • Editing • Compiling • Linking with precompiled files • Object files & Library modules • Loading and executing • Viewing the behavior of the program

  47. Software Development Cycle

  48. IDEs • Integrated Development Environments or IDEs • Supports the entire software development cycle • E.g., MS Visual C++, Dev-C++, Code Warrior • Provides all the capabilities for developing software • Editor • Compiler • Linker • Loader • Debugger • Viewer

  49. Engineering Software • Software engineering • Area of computer science concerned with building large software systems • Challenge for software: • Tremendous advances in hardware have not been accompanied by comparable advances in software

  50. Complexity Trade-off • System complexity tends to grow as the system becomes more user friendly

More Related