Unformatted text preview:

Programming• it's hard to do the programming to get something done• details are hard to get right, very complicated, finicky• not enough skilled people to do what is needed• therefore, enlist machines to do some of the work– leads to programming languages• it's hard to manage the resources of the computer• hard to control sequences of operations• in ancient times, high cost of having machine be idle• therefore, enlist machines to do some of the work– leads to operating systemsEvolution of programming languages• 1940's: machine level– use binary or equivalent notations for actual numeric values• 1950's: "assembly language"– names for instructions: ADD instead of 0110101, etc.– names for locations: assembler keeps track of where things are in memory; translates this more humane language into machine language– this is the level used in the "toy" machine– needs total rewrite if moved to a different kind of CPUloop get # read a numberifzero done # no more input if number is zeroadd sum # add in accumulated sumstore sum # store new value back in sumgoto loop # read another numberdone load sum # print sumprintstopsum 0 # sum will be 0 when program startsinstructionsassemblerassembly langprogramEvolution of programming languages, 1960's• "high level" languages -- Fortran, Cobol, Basic– write in a more natural notation, e.g., mathematical formulas– a program ("compiler", "translator") converts into assembler– potential disadvantage: lower efficiency in use of machine– enormous advantages:accessible to much wider population of usersportable: same program can be translated for different machinesmore efficient in programmer timesum = 010 read(5,*) numif (num .eq. 0) goto 20sum = sum + numgoto 1020 write(6,*) sumstopendcompilerassemblerFortran programinstructionsEvolution of programming languages, 1970's• "system programming" languages -- C– efficient and expressive enough to take on any programming taskwriting assemblers, compilers, operating systems– a program ("compiler", "translator") converts into assembler– enormous advantages:accessible to much wider population of programmersportable: same program can be translated for different machinesfaster, cheaper hardware helps make this happen#include <stdio.h>main() {int num, sum = 0;while (scanf("%d", &num) != -1 && num != 0)sum += num;printf("%d\n", sum);}C compilerassemblerC programinstructionsC code compiled to assembly language (SPARC)#include <stdio.h>main() {int num, sum = 0;while (scanf("%d", &num) != -1&& num != 0)sum = sum + num;printf("%d\n", sum);}(You are not expected to understand this!).LL2: add %fp, -20, %g1sethi %hi(.LLC0), %o5or %o5, %lo(.LLC0), %o0mov %g1, %o1call scanf, 0mov %o0, %g1cmp %g1, -1be .LL3ld [%fp-20], %g1cmp %g1, 0be .LL3ld [%fp-24], %g1ld [%fp-20], %o5add %g1, %o5, %g1st %g1, [%fp-24]b .LL2.LL3: sethi %hi(.LLC1), %g1or %g1, %lo(.LLC1), %o0ld [%fp-24], %o1call printf, 0mov %g1, %i0retC code compiled to assembly language (x86)#include <stdio.h>main() {int num, sum = 0;while (scanf("%d", &num) != -1&& num != 0)sum = sum + num;printf("%d\n", sum);}.L2: leal -4(%ebp), %eaxmovl %eax, 4(%esp)movl $.LC0, (%esp)call scanfcmpl $-1, %eaxje .L3cmpl $0, -4(%ebp)je .L3movl -4(%ebp), %edxleal -8(%ebp), %eaxaddl %edx, (%eax)jmp .L2.L3: movl -8(%ebp), %eaxmovl %eax, 4(%esp)movl $.LC1, (%esp)call printfleaveretEvolution of programming languages, 1980's• "object-oriented" languages: C++– better control of structure of really large programsbetter internal checks, organization, safety– a program ("compiler", "translator") converts into assembler or C– enormous advantages:portable: same program can be translated for different machinesfaster, cheaper hardware helps make this happen#include <iostream>main() {int num, sum = 0;while (cin >> num && num != 0)sum += num;cout << sum << endl;}Evolution of programming languages, 1990's• "scripting", Web, component-based, ...: Java, Perl, Python, Visual Basic, Javascript, ...– write big programs by combining components already written– often based on "virtual machine": simulated, like fancier toy computer– enormous advantages:portable: same program can be translated for different machinesfaster, cheaper hardware helps make this happenvar sum = 0, num; // javascriptnum = prompt("Enter new value, or 0 to end")while (num != 0) {sum = sum + parseInt(num)num = prompt("Enter new value, or 0 to end")}alert("Sum = " + sum)Evolution of programming languages, 2000's• so far, more of the same– more specialized languages for specific application areasFlash/Actionscript for animation in web pages– ongoing refinements / evolution of existing languagesC, C++, Fortran, Cobol all have new standards in last few years• copycat languages– Microsoft C# strongly related to Java– scripting languages similar to Perl, Python, et al• better tools for creating programs without as much programming– mixing and matching components from multiple languagesWhy so many programming languages?• every language is a tradeoff among competing pressures– reaction to perceived failings of others; personal taste• notation is important– "Language shapes the way we think and determines what we can think about."Benjamin Whorf– the more natural and close to the problem domain, the easier it is to get the machine to do what you want• higher-level languages hide differences between machines and between operating systems• we can define idealized "machines" or capabilities and have a program simulate them -- "virtual machines"– programming languages are another example of Turing


View Full Document

Princeton COS 109 - Programming

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