100 likes | 152 Views
Assembly Language. .text .globl fact .type fact, @function fact: pushl %ebp movl %esp, %ebp subl $4, %esp movl $1, -4(%ebp) .L2: cmpl $0, 8(%ebp) jg .L4 jmp .L3 .L4:
E N D
Assembly Language .text .globl fact .type fact, @function fact: pushl %ebp movl %esp, %ebp subl $4, %esp movl $1, -4(%ebp) .L2: cmpl $0, 8(%ebp) jg .L4 jmp .L3 .L4: movl -4(%ebp), %eax imull 8(%ebp), %eax movl %eax, -4(%ebp) leal -4(%ebp), %eax decl (%eax) jmp .L2 .L3: movl -4(%ebp), %eax leave ret .size fact, .-fact • Specific to each machine • Extremely low level • Somewhat cryptic
FortranJohn Backus, 1957 READ INPUT TAPE 5, 501, IA, IB, IC 501 FORMAT (3I5) IF (IA) 777, 777, 701 701 IF (IB) 777, 777, 702 702 IF (IC) 777, 777, 703 703 IF (IA+IB-IC) 777,777,704 704 IF (IA+IC-IB) 777,777,705 705 IF (IB+IC-IA) 777,777,799 777 STOP 1 799 S = FLOATF (IA + IB + IC) / 2.0 AREA = SQRT( S * (S - FLOATF(IA)) * (S - FLOATF(IB)) * + (S - FLOATF(IC))) WRITE OUTPUT TAPE 6, 601, IA, IB, IC, AREA 601 FORMAT (4H A= ,I5,5H B= ,I5,5H C= ,I5,8H AREA= ,F10.2, + 13H SQUARE UNITS) STOP END • Compound expressions • Statements • Compilation
LispJohn McCarthy, 1958 (defun length (lst) (if (null? lst) 0 (+ 1 (length lst)))) (defun append (lst1 lst2) (if (null? lst1) lst2 (cons (car lst1) (append (cdr lst1) lst2)))) • Interpreted • Dynamically typed • Lists • Heap-based memory allocation • Garbage collection
Algol 60International Committee, 1960 procedure Absmax(a) Size:(n, m) Result:(y) Subscripts:(i, k); value n, m; array a; integer n, m, i, k; real y; begin integer p, q; y := 0; i := k := 1; for p:=1 step 1 until n do for q:=1 step 1 until m do if abs(a[p, q]) > y then begin y := abs(a[p, q]); i := p; k := q end end Absmax • Block structured procedures • Familiar control structures • Arrays and records • Statically typed
SimulaOle-Johan Dahl & Kristen Nygaard, 1967 Begin Class Glyph; Virtual: Procedure print Is Procedure print;; Begin End; Glyph Class Line (elements); Ref (Glyph) Array elements; Begin Procedure print; Begin Integer i; For i:= 1 Step 1 Until UpperBound (elements, 1) Do elements (i).print; OutImage; End; End; • Classes, objects, inheritance • Garbage collection • Extension of Algol 60
CDennis Richie, 1972 factorial (n) { res = 1; while (n > 0) { res *= n; n –= 1; } return res; } • Terse (and by now familiar) syntax • Low-level access to machine resources • Minimal (and unsafe) static typing • Mixed stack/heap memory model • Pointers
C++Bjarne Stroustrup, 1979 class Bird { public: virtual void outputName() { cout << "a bird"; } virtual ~Bird() {} }; class Swan: public Bird { public: void outputName() { cout << "a swan"; } }; • “C with classes” • Classes and inheritance as in Simula • Pointers, unsafe static types, memory • model, low-level access as in C
JavaSun Microsystems, 1995 public class Hello extends GenericServlet { public void service (ServletRequest request,ServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); final PrintWriter pw = response.getWriter(); pw.println("Hello, world!"); pw.close(); } } • Syntax borrowed from C and C++ • Inheritance borrowed from Simula and Smalltalk • Memory model borrowed from Lisp • Safe mixture of static/dynamic type systems • Platform independence via byte code interpreter
C#Microsoft, 2002 using System; class Calendar { static int GetYearFromUser () { int year = 1900; while (true) { Console.Write("Which year? "); year = Int32.Parse(Console.ReadLine()); if (year >= 1900) return year; Console.WriteLine("The year must be at least 1900."); } } } • Approach borrowed wholesale from Java • “A better Java”? • Integrated into the .net framework