Languages and tools. BY SA machine code.
-
Upload
kristian-burns -
Category
Documents
-
view
222 -
download
0
Transcript of Languages and tools. BY SA machine code.
languages and tools
BY
SA
machine code
assembly
section .text
global main
main:mov eax, 4 ;system call number (sys_write)mov ebx, 1 ;first argument: file handle (stdout)mov ecx, msg ;second argument: pointer to message to
writemov edx, len ;third argument: message lengthint 0x80 ;call kernel
mov eax, 1 ;system call number (sys_exit)mov ebx, 0 ;first syscall argument: exit codeint 0x80 ;call kernel
section .data
msg db "Hello, world!", 0xa len equ $ - msg
NASM (Netwide Assembler) GAS (Gnu Assembler) MASM (Microsoft Macro Assembler)
hello.asm(source)
hello.o(object file)
hello (executable)
assembler linker
foo.asm foo.o
baz
assembler
bar.asm bar.o
assembler
linker
dynamic linking
.so (Linux)
.dll (Windows)
(linking at runtime)
low-level• precise control• efficiency
high-level• expressiveness• portability
compiler
foo.c foo.o
baz
compiler
bar.c bar.o
compiler
linker
foo.asm foo.o
baz
assembler
bar.c bar.o
compiler
linker
interpreter
hello(source)
interpreter
foo
interpreter
bar
88 + 52 – 98 * (-3 + 5)
88 + 52 – 98 * (-3 + 5) 93
88 + 52 – 98 * (-3 + 5) -7
88 + 52 – 98 * (-3 + 5) 16
as foo 1 + 21 + foo 4
hello.java(source)
hello.class(bytecode)
compiler virtual machine
hello.java(source)
hello.class(bytecode)
compilerVM with JIT
(Just-in-time)
(machine code)
garbage collection
function factorial n as val 1 while (gt n 1) # error when n is not a number as val (mul n val) as n (sub n 1) return val
(factorial true) # improper type
Type error:
function num:factorial num:n as num:val 1 while (gt n 1) as val (mul n val) as n (sub n 1) return val
(factorial true) # improper type
Static typing:
function num:factorial num:n as num:val 1 while (gt n 1) as val (mul n val) as n (sub n 1) return val
(factorial (foo))
Static typing:
as list:foo (list “hello” 14 8)as num:bar (get foo 1) # unknown type
as numList:foo (numList 5 14 8)as num:bar (getNum foo 1)
polymorphism
(print “hello”)(print 100)(print false)
(accepts varied number and/or types of inputs)
function foo a b if (isNum a) … else …
(foo 3 true)(foo “hello” true)
function foo a b if (isNull b) … else …
(foo 3 true)(foo “hello” null)
function foo a b if (isNull b) … else …
(foo 3 true)(foo “hello”)
function num:foo num:a bool:b …
function bool:foo str:a bool:b …
function str:foo str:a …
function num:foo num:a bool:b …
function bool:foo str:a bool:b …
function str:foo str:a # illegal …
function num:foo str:a # illegal …
function num:foo num:a bool:b …
function bool:foo str:a bool:b …
function str:foo str:a …
(foo “hello”)(foo 3 true)(foo “hello” false)
function num:foo num:a bool:b …
function bool:foo str:a bool:b …
function str:foo str:a …
as str:x (foo “hello”)
function foo a if (isNum a) … else …
as bar 4if x as bar false(foo bar)
function num:foo bool:a …function num:foo num:a …
as num:bar 4 if x as bar false # illegal(foo bar)
function num:foo bool:a …function num:foo num:a …
(foo (ack))
Strong typing:
• Operations only treat a piece of data appropriately to its type.
Weak typing:
• Possible to modify any bytes of data in any way.
paradigms• imperative (do modify state)• functional (don’t modify state)
• procedural (action-centered design)• object-oriented (data-centered design)
• syntax• semantics• libraries• idioms• tools
• compiler• linker• interpreter• text editor • debugger• profiler• version control• IDE (Integrated Developer Environment)
C• 1970’s• static, compiled to machine code• “portable assembly”
#include <stdio.h>
int main(){ printf(“Hello, world!\n"); return 0;}
C++• 1980’s• superset of C (almost)• C with OOP
#include <iostream>
int main() { std::cout << "Hello, world!\n"; return 0; }
Objective-C• 1980’s• superset of C• C with OOP• mostly used by Apple
#import <stdio.h>
int main(){ printf(“Hello, world!\n”); return 0;}
Java• 1990’s by Sun Microsystems• static• OOP• C-style syntax• compiled to bytecode, run by VM• JVM (Java Virtual Machine)
public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, world!"); }}
C#• 2001 by Microsoft• static• OOP• C-style syntax• compiles to bytecode, run by VM• CLR (Common Language Runtime)
using System;
class ExampleClass { static void Main() { Console.WriteLine("Hello, world!"); }}
Visual Basic• 1990’s by Microsoft• now basically C# with different syntax
Module Module1 Sub Main() Console.WriteLine("Hello, world!") End SubEnd Module
Perl• 1990’s• dynamic• OOP (weak)• interpreted
print "Hello, world!\n";
Python
print("Hello, world!\n”)
• 1990’s• dynamic• OOP• interpreted• indentation-sensitive
Ruby
puts “Hello, world!\n”
• 1990’s• dynamic• OOP• interpreted• generate webpages
PHP
<?php Print "Hello, World!";?>
• 1990’s• dynamic• OOP (weak)• interpreted• generate webpages
Javascript• 1990’s• dynamic• OOP (prototypes)• interpreted• C-style syntax• embedded in webpages
alert(“Hello, world!\n”);
Fortran
• 1950’s• static• compiled• many revisions• science and engineering
program hello print *, “Hello World!”end program hello
Lisp• 1950’s• dynamic• interpreted• prefix notation• meta-programming (macros)• dialects (Common Lisp, Scheme, Clojure)
(print “Hello, world!\n”)
efficiency
• interpretation• dynamic typing• garbage collection
efficiency1) assembly, C, C++,
Objective-C, Fortran2) Java, C#3) Perl, Python, Ruby,
PHP, Javascript
portability• CPU• libraries• capabilities
• functional languages (Haskell, Scala, ML, F#)• logic languages (Prolog)• shell languages (BASH)• scripting languages (Perl, Python)• data languages (HTML, XML)• query languages (SQL)• domain-specific languages• graphical languages
(Brian Will)created by
http://brianwill.net/