E N D
languages and tools
SA BY
section .textglobal mainmain: 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 write mov edx, len ;third argument: message length int 0x80;call kernel mov eax, 1;system call number (sys_exit) mov ebx, 0;first syscall argument: exit code int 0x80;call kernelsection .data msg db"Hello, world!", 0xa len equ $ - msg
NASM(Netwide Assembler) GAS(Gnu Assembler) MASM(Microsoft Macro Assembler)
assembler linker hello (executable) hello.asm (source) hello.o (object file)
assembler linker foo.asm foo.o assembler baz bar.o bar.asm
dynamic linking (linking at runtime) .so (Linux) .dll (Windows)
high-level • expressiveness • portability low-level • precise control • efficiency
compiler linker foo.c foo.o compiler baz bar.c bar.o
assembler linker foo.asm foo.o compiler baz bar.o bar.c
interpreter hello (source)
interpreter foo bar
88 + 5 2 – 9 8 * (-3 + 5)
93 88 + 5 2 – 9 8 * (-3 + 5)
-7 88 + 5 2 – 9 8 * (-3 + 5)
16 88 + 5 2 – 9 8 * (-3 + 5)
4 • as foo 1 + 2 1 + foo
compiler virtual machine hello.java (source) hello.class (bytecode)
VM with JIT (Just-in-time) compiler hello.java (source) hello.class (bytecode) (machine code)
function factorial n • as val1 • while (gtn1) # error when n is not a number • as val(mulnval) • as n(subn1) • return val • (factorial true) # improper type Type error:
function num:factorial num:n • as num:val1 • while (gtn1) • as val(mulnval) • as n(subn1) • return val • (factorial true) # improper type Static typing:
function num:factorial num:n • as num:val1 • while (gtn1) • as val(mulnval) • as n(subn1) • return val • (factorial (foo)) Static typing:
as list:foo(list“hello” 14 8) • as num:bar (getfoo 1) # unknown type
as numList:foo(numList5 14 8) • as num:bar (getNumfoo 1)
(accepts varied number and/or types of inputs) polymorphism • (print“hello”) • (print100) • (printfalse)
function foo a b • if (isNuma) • … • else • … • (foo 3 true) • (foo “hello” true)
function foo a b • if (isNullb) • … • else • … • (foo 3 true) • (foo “hello”null)
function foo a b • if (isNullb) • … • 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 • … • asstr:x (foo “hello”)
function foo a • if (isNuma) • … • else • … • asbar4 • ifx • asbarfalse • (foo bar)
function num:foo bool:a • … • function num:foo num:a • … • asnum:bar4 • ifx • asbarfalse # illegal • (foo bar)
function num:foo bool:a • … • function num:foo num:a • … • (foo (ack))
Weak typing: Strong typing: • Possible to modify any bytes of data in any way. Operations only treat a piece of data appropriately to its type.
paradigms imperative (domodify state) functional (don’tmodify 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)