Unformatted text preview:

Programming ConceptsWhat are Programs?Machine LanguagesMachine Languages (2)Assembly LanguagesAssemblersBirth of High-Level LanguagesHigh-Level LanguagesCompilersFrom Problems to Programs: ProblemsFrom Problems to Programs: PrecisionFrom Problems to Programs: InputsFrom Problems to Programs: OutputsFrom Problems to Programs: ComputabilityFrom Problems to Programs: AlgorithmsAlgorithms: Example 1Designing AlgorithmsFrom Problems to Programs: ProgramsAmbiguity in LanguagesPrecision in Programming LanguagesSyntax and SemanticsLearning To ProgramAbout PerlMore About PerlCompilers Versus InterpretersIs Perl Compiled or Interpreted?Running Perl: Method 1Running Perl: Method 2Running Perl: Method 3Slide 30Where Do We Go From HereCopyright 2006 Stewart WeissCopyright 2009 Stewart WeissProgramming ConceptsProgramming ConceptsPrograms, Languages, and Algorithms2 CSci 132 Practical UNIX with PerlWhat are programs?A program is a precise sequence of instructions, intended to solve a particular problem, that can be carried out by a machine.Programs do not have to be run on computers; even before the age of computers, the Jacquard loom used something like punchcards to automate the action of a loom. These punchcards were effectively programs to control the loom. (You can see a short video about it here:https://www.youtube.com/watch?v=lwozgRPLVC8 )The important part is that the instructions are unambiguous and precise.3 CSci 132 Practical UNIX with PerlMachine instructionsA computer is a machine that can carry out a set of precise, unambiguous instructions, called machine instructions. Because computers are digital, electronic devices, machine instructions are patterns of 0's and 1's. For example, 000000 00001 00010 00110 00000 100000 is a 32-bit instruction to add registers 1 and 2 and store the result in register 6 on the MIPS processor. The processor is the part of the computer that executes instructions. A register is a storage cell inside the processor.4 CSci 132 Practical UNIX with PerlMachine languagesThe complete collection of machine instructions that a processor can carry out is called its instruction set. Machine language is the language that defines machine instruction programs. Machine language is to the instruction set as written language is to a dictionary – the instruction set is the collection of all instructions, like the words in the dictionary; and machine language specifies how the instructions are put together to make programs, in the same way that a written language has rules for how sentences are created.5 CSci 132 Practical UNIX with PerlAssembly languagesIn the dawn of the age of modern computers, computer designers invented assembly language. Assembly language made it possible to write computer instructions in a more human-friendly form. The machine instruction000000 00001 00010 00110 00000 100000would be written in an assembly language as something likeadd $6, $1, $26 CSci 132 Practical UNIX with PerlAssemblersIt is convenient to be able to write instructions in a more readable form, but to make this possible, someone had to create a software program that would read the assembly language program and convert it to machine language.The software program that reads an assembly language program and creates a machine language program from it is called an assembler. It assembles the machine code from the human-readable instructions.7 CSci 132 Practical UNIX with PerlBirth of high-level languagesAssembly language programming was still very limiting. Imagine trying to write a program containing tens of thousands of instructions using instructions like add $6, $1, $2In 1957, a team from IBM invented the first high-level language which they named (FORTRAN). FORTRAN made it possible to write instructions that were more like the mathematical equations to which people were accustomed. FORTRAN paved the way for other high-level languages.8 CSci 132 Practical UNIX with PerlHigh-level languagesIn a high-level language, one can write an instruction such asz = x + y;that means, "add the number stored in x to the number stored in y and put the sum into a storage cell named z."High-level languages also made it easier to get input into programs and write output from programs, with instructions like print z;9 CSci 132 Practical UNIX with PerlCompilersA high-level language instruction is easy for a programmer to write, but it has to get converted into machine instructions that can be executed by the computer.An instruction like "z = x + y" would be translated first into an assembly language instruction sequence such as movl x, %eaxaddl y, %eaxmovl %eax, zwhich would be assembled into machine instructions.The program that translates from high-level language to assembly language is called a compiler.10 CSci 132 Practical UNIX with PerlFrom problems to programs: problemsPrograms are written to solve problems. This begs the question, "What does 'solving a problem' actually mean?"To solve a problem using a computer, the problem has to be stated precisely.This may sound obvious and it may sound easy, but it is often not.11 CSci 132 Practical UNIX with PerlFrom problems to programs: precision For example, the problem, "find the shortest distance from New York to Chicago by car" is not very precise. Does it mean, on major highways only? If not on highways, then on all possible roads, even private ones? If not, then what kinds of roads? Where in New York does it start? Where in Chicago does it end? Is distance in kilometers?12 CSci 132 Practical UNIX with PerlFrom problems to programs: inputsThe problem is usually stated in a more general way. You would probably not want to know the distance from New York to Chicago only, but you would want to have a program that, given any two cities, finds that distance.Thus, a problem is a general statement that can have many possible input values. In this case, (New York, Chicago) would be an input to the problem. So would (Boston, Miami) for example.In this case, the input is a pair of names of cities.13 CSci 132 Practical UNIX with PerlFrom problems to programs: outputsFor each input value, there must exist a single, correct output value, otherwise we cannot define a solution. In our travel route problem, the output is a single number, such as 1023 miles. It might also be reasonable for it to be a range, such as 1020-1030 miles, or 1025, with error ±5. This may be acceptable in certain circumstances. In either case, the output must be a unique,


View Full Document

CUNY CSCI 132 - Programming Concepts

Download Programming Concepts
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 Concepts 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 Concepts 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?