Programmeerimiskeeled. Sissejuhatus informaatikasse Aivar Annamaa 28. november 2012
|
|
- Lynn Gilmore
- 6 years ago
- Views:
Transcription
1 Programmeerimiskeeled Sissejuhatus informaatikasse Aivar Annamaa 28. november 2012
2 Mis on programmeerimiskeeled? Miks on prog.keeli nii palju? Kuidas prog.keeli tehakse?
3 Milleks programmeerimiskeeled?
4 Ülesanne => masin
5
6 Andmed Masin Väljund
7 Andmed Masin Programm Väljund
8 ENIAC 1946
9
10 Ülesanne => programm => masin
11 .equ lower,12.equ upper, 16 #;; [ebp+8] is start address, [ebp+12] is end address of partition _quicksort: push %ebp mov %ebp,%esp #pushad movl %ebx,12(%ebp) #; start of partition #;; find pivot index: ploop: cmp %ebx,16(%ebp) #; last cell of partition? jge qretrn #; no pivot, so exit movl %eax, 4(%ebx) #; A[i+1] cmp %eax, (%ebx) #; A[i] jl pfound #; A[i]>A[i+1], pivot found addl %ebx,4 #; next cell jmp ploop pfound: #;; at this point, ebx holds mem address of pivot #;; now partition into < and >= pivot via repeated swapping. #;; use two counters: ebx and esi. ebx always points to the #;; first cell of second partition (what's >= pivot) movl %ecx,(%ebx) #; save pivot in ecx movl %esi,%ebx addl %esi,4 #; next cell tloop: #; partitioning loop cmp %ecx,(%esi) #; compare pivot against element jle noswap #; no swap if element >=pivot #;; swap [ebx] and [esi], advance both movl %eax,(%ebx) pushl %eax #; use stack as temp movl %eax,(%esi) movl (%ebx),%eax popl %eax movl (%esi),%eax #; done swap addl %ebx,4 #; next cell must still be >= pivot noswap: addl %esi,4 #; goto next cell, preserve ebx cmp %esi,16(%ebp) #; end of partition? jle tloop #; next iteration of partition loop #;; #;; #;; at this point, ebx holds start addr of second partition (could be pivot itself). make recursive calls to quickaux: #;; first partition: subl %ebx,4 pushl %ebx #; movl %eax,12(%ebp) pushl %eax #; call _quicksort addl %esp,8 #; #;; second partition movl %eax,16(%ebp) pushl %eax #; addl %ebx,4 push %ebx #; call _quicksort addl %esp,8 qretrn: end of first paritition start of first partition deallocate params end of second partition start of second partition Assembler-keeled cmp %ecx,(%esi) jle noswap movl %eax,(%ebx) pushl %eax movl %eax,(%esi) movl (%ebx),%eax popl %eax movl (%esi),%eax addl %ebx,4
12 Ülesanne => programm => masin
13
14 Fortran (1957) i = 1 sum = 0 10 do 20 i = 1, 50 if (i.gt. 10) goto 30 sum = sum + i 20 continue 30 if (i. le. 20) then sum = sum 1 goto 20 else sum = 2*sum endif write(*,*) 'Sum =', sum
15 Transleerimine
16 Kui palju on prog.keeli?
17
18
19 The Zen of Python >>> import this The Zen of Python, by Tim Peters Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren't special enough to break the rules. Although practicality beats purity. Errors should never pass silently. Unless explicitly silenced. In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. Now is better than never. Although never is often better than *right* now. If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. Namespaces are one honking great idea -- let's do more of those!
20 Perl: TIMTOWTDI "There Is More Than One Way To Do It"
21 Paindlik vs. täpne/range
22 def arvuta(a, b): if a == 23: return 3 else: return a / b print(arvuta(23, "tere"))
23 public class RangeLugu { public static void main(string[] args) { System.out.println(divide(23, "tere")); } private static int arvuta(int a, int b) { if (a == 23) { return 3; } else { return a / b; } } }
24 requires 0 < amount && amount <= balance; //@ assignable balance; //@ ensures balance == \old(balance) - amount; public void debit(final int amount) { this.balance -= amount; } //@ requires!islocked; //@ ensures \result == balance; //@ also //@ requires islocked; //@ signals_only BankingException; public /*@ int getbalance() throws BankingEx { if (!this.islocked) { return this.balance; } else { throw new BankingException(); } }
25 Universaalne vs spetsiifiline
26 Prolog (1972) mother_child(trude, sally). father_child(tom, sally). father_child(tom, erica). father_child(mike, tom). sibling(x, Y) :- parent_child(z, X), parent_child(z, Y). parent_child(x, Y) :- father_child(x, Y). parent_child(x, Y) :- mother_child(x, Y).?- sibling(sally, erica). Yes
27 LISP (1958) Scheme Common Lisp Clojure (def x (+ 3 (* 4 2) 6)) John McCarthy
28 Domeenispetsiifilised keeled (DSL-s)
29 HTML <span style="font-size:10px; color: gray"> AEGEE-Tallinn<br/> <a href=" style="color:gray"> </span> </td> <!-- Contents > <td class="right"> <p> <a class='pic right' href='pics/tree_big.jpg'><img src='pics/tree_sm.jpg' alt='tree' /></a> </p> <div style="font-size:10px">aegee-tallinn proudly presents:</div> <div style="font-size:28px; font-weight:bold; margin-top:25px; margin-bottom:5px">
30 CSS body.toc span.remark { color: gray; font-style: normal; font-weight: 900; } /* LAYOUT *** */ body { text-align:center; } html, body { height: 100%; padding: 0px; margin: 0px; }
31 SQL (1974) SELECT FROM ON GROUP Book.title, COUNT(*) AS Authors Book JOIN Book_author Book.isbn = Book_author.isbn BY Book.title; Title SQL Examples and Guide The Joy of SQL An Introduction to SQL Pitfalls of SQL Authors
32
33 Keelte rühmitamine Imperatiivne vs. deklaratiivne Dünaamiline vs. staatiline Üldotstarbeline vs. domeenispetsiifiline
34
35
36 Universaalne programmeerimiskeel?
37 Newspeak (George Orwell, "1984")
38 Programmeerime mõnes loomulikus (nt. inglise) keeles?
39
40 Clojure Haskell Io Prolog Scala Erlang Ruby
41 Millest programmeerimiskeeled tehtud on?
42 KJK - Kilpkonna Juhtimise Keel E V E V E
43 Kilpkonna juhtija import turtle f = open("kilpkonn.txt", encoding="utf-8") for käsk in f: osad = käsk.split() tüüp = osad[0] argument = int(osad[1]) if tüüp == 'E': turtle.forward(argument) elif tüüp == 'T': turtle.backward(argument) elif tüüp == 'V': turtle.left(argument) elif tüüp == 'P': turtle.right(argument) else: print("tundmatu käsk:", käsk) f.close() turtle.exitonclick()
44 Mis on loomulik keel? Tähestik Morfoloogia (sõnade moodustamise reeglid) Süntaks (lausete moodustamise reeglid) Avatud sõnavara (sõnad koos tähendusega) Mis on keele eesmärk?
45 Formaalne keel Mingi alfabeedi põhjal koostatud sõnade (programmide) hulk {a, aa, aaa, aaaa,...} {ab, ba, aa, bb} {0, 1, 10, 11, 101, 110, 111,...} {..., print ( "tere" ),...} Tavaliselt on igale sõnale (programmile) määratud ka mingi tähendus e. semantika Kuidas keelt defineerida? Kas loetleme kõik programmid ja nende tähendused?
46 Morfoloogia ja süntaks Reeglid, mis määravad kuidas on lubatud teha tähtedest sõnu sõnadest lauseid Võimaldavad kirjeldada lõpmatut hulka variatsioone Loomuliku keele morfoloogia ja süntaks kirjeldatakse tavaliselt loomulikus keeles Formaalse keele korral...
47 Pythoni süntaksi fragment if_stmt: 'if' test ':' suite ['else' ':' suite] test : or_test ['if' or_test 'else' test] or_test: and_test ('or' and_test)* suite :... if_stmt term : factor (('*' '/' '%' '//') factor)* factor : ('+' '-' '~') factor power... NAME : ('A'..'Z' 'a'.. 'z' '_')*
48 Konkreetne vs. abstraktne süntaks x = 3 * (y - z) (= x (* 3 (- y z)))
49 Süntaksi analüüs (ing.k parsing)
50 Tähendus e. semantika Interpretaatori kaudu (operatsiooniline semantika) Translaatori kaudu (denotatsiooniline semantika)
51 Interpreteerimine Kilpkonna interpretaator Python CPU Küllaltki lihtne realiseerida Samu asju tuleb mitu korda interpreteerida
52 Transleerimine (e. kompileerimine) javac gcc masm Keerulisem realiseerida Võtab aega Lähtekeele tõlgendamist pole vaja teha igal käivitusel
53
54 KJK translaator Sisend: fail KJK käskudega Väljund: Pythoni fail
55 Palju tasemeid KJK Python C Assembler Masinkood JIT
56 Õiged primitiivid + kombineerimisreeglid => misiganes! Virtuaalne masin NAND + False Protsessor Assembler Prog. keel OP-süsteem Tetris html
57 ... kõik see jookseb op-süsteemis prog keelel... CPU-s... Veel üks näide:
58 Formaalne keel vs loomulik keel Mis on formaalse keele eesmärk? Kas formaalsetel keeltel on mõtet ilma arvutita?
59 Formaalne keel vs. loomulik keel Formaalne keel ei luba jätta asju hägusaks Probleem?
60 Programmide staatiline analüüs lvor/
61 Programmeerimiskeeled ja ATI Uurimissuunad Funktsionaalsed keeled Kategooriate teooria Programmide staatiline analüüs Tüübiteooria
62 Python (1991) def ühend(j1, j2): tulemus = [] for element in j1: if not (element in tulemus): tulemus.append(element) for element in j2: if not (element in tulemus): tulemus.append(element) return tulemus print(ühend([1, 2, 3, 2], [1, 6, 6])) Guido van Rossum (BDFL)
63 Java (1995) JVM Applets Web Java SE Java EE, Spring Android Seadmed James Gosling
64
65 JavaScript (1995) JS on igas arvutis! WEB 2.0 mootor... <script> function fact(n) { if (n == 0) { return 1; } return n * fact(n 1); } </script>...
66 PHP (1995) <html> <body> <ul> Rasmus Lerdorf <?php $ylesanded = file("todo.txt"); if (isset($_post['ylesanne'])) { $ylesanded[] = $_POST['ylesanne']; file_put_contents("todo.txt", join("\n", $ylesanded)); }...
67 Ruby (1995) class Person attr_reader :name, :age def = name, age end def <=> person.age end def to_s "#@name (#@age)" end end group = [ Person.new("Bob", 33), Person.new("Chris", 16), Person.new("Ash", 23) ] まつもとゆきひろ (Matz)
68 Perl (1987) "There's more than one way to do it" if (m/\w/) { = split (//); my $A = my $Z = print $A; if (defined ($Z)) { my $i = $#w+1; while ($i--) { my $j = int rand Larry Wall
69 C #include <stdio.h> int main(void) { printf("hello,world\n"); return 0; }... int ar[5], *ip; ip = &ar[3];
70 C++ (1983) Bjarne Stroustrup... template <class mytype> mytype GetMax (mytype a, mytype b) { return (a>b?a:b); }...
71 Objective-C (1983) #import <stdio.h> #import "Fraction.h" int main( int argc, const char *argv[] ) { Fraction *frac = [[Fraction alloc] init]; [frac setnumerator: 1]; [frac setdenominator: 3]; printf( "The fraction is: " ); [frac print]; printf( "\n" ); [frac release]; return 0; }
72 C# using System; public class HelloWorld { public static void Main(string[] args) { Console.Write("Hello World!"); } }
73 Pascal (1970)
74 Haskell (1990) quicksort :: Ord a => [a] -> [a] quicksort [] = [] quicksort (p:xs) = (quicksort lesser) ++ [p] ++ (quicksort greater) where lesser = filter (< p) xs greater = filter (>= p) xs
75 Whitespace (2003)
administrivia today start assembly probably won t finish all these slides Assignment 4 due tomorrow any questions?
administrivia today start assembly probably won t finish all these slides Assignment 4 due tomorrow any questions? exam on Wednesday today s material not on the exam 1 Assembly Assembly is programming
More informationOOP and Scripting in Python
DIEE - Università degli Studi di Cagliari OOP and Scripting in Python Introduction Giuliano Armano DIEE Univ. di Cagliari Python Roots... Object Oriented Programming (C++, Modula-3, ABC, Icon) Scripting
More informationA polyglot day: learning from language paradigms. Benson Joeris Kathleen Dollard
A polyglot day: learning from language paradigms Benson Joeris Kathleen Dollard What if you understood all the paradigms that define modern languages? You could program better in your base language, choose
More informationCPS104 Recitation: Assembly Programming
CPS104 Recitation: Assembly Programming Alexandru Duțu 1 Facts OS kernel and embedded software engineers use assembly for some parts of their code some OSes had their entire GUIs written in assembly in
More informationThe Hardware/Software Interface CSE351 Spring 2013
The Hardware/Software Interface CSE351 Spring 2013 x86 Programming II 2 Today s Topics: control flow Condition codes Conditional and unconditional branches Loops 3 Conditionals and Control Flow A conditional
More informationSecond Part of the Course
CSC 2400: Computer Systems Towards the Hardware 1 Second Part of the Course Toward the hardware High-level language (C) assembly language machine language (IA-32) 2 High-Level Language g Make programming
More informationAssembly Language: Function Calls
Assembly Language: Function Calls 1 Goals of this Lecture Help you learn: Function call problems: Calling and returning Passing parameters Storing local variables Handling registers without interference
More informationAS08-C++ and Assembly Calling and Returning. CS220 Logic Design AS08-C++ and Assembly. AS08-C++ and Assembly Calling Conventions
CS220 Logic Design Outline Calling Conventions Multi-module Programs 1 Calling and Returning We have already seen how the call instruction is used to execute a subprogram. call pushes the address of the
More informationAssembly Language: IA-32 Instructions
Assembly Language: IA-32 Instructions 1 Goals of this Lecture Help you learn how to: Manipulate data of various sizes Leverage more sophisticated addressing modes Use condition codes and jumps to change
More informationWhat the CPU Sees Basic Flow Control Conditional Flow Control Structured Flow Control Functions and Scope. C Flow Control.
C Flow Control David Chisnall February 1, 2011 Outline What the CPU Sees Basic Flow Control Conditional Flow Control Structured Flow Control Functions and Scope Disclaimer! These slides contain a lot of
More informationAssembly Language: Function Calls" Goals of this Lecture"
Assembly Language: Function Calls" 1 Goals of this Lecture" Help you learn:" Function call problems:" Calling and returning" Passing parameters" Storing local variables" Handling registers without interference"
More informationAssembly Language: Function Calls" Goals of this Lecture"
Assembly Language: Function Calls" 1 Goals of this Lecture" Help you learn:" Function call problems:" Calling and urning" Passing parameters" Storing local variables" Handling registers without interference"
More informationAssembly Language: Function Calls. Goals of this Lecture. Function Call Problems
Assembly Language: Function Calls 1 Goals of this Lecture Help you learn: Function call problems: Calling and urning Passing parameters Storing local variables Handling registers without interference Returning
More informationMachine-Level Programming II: Control Flow
Machine-Level Programming II: Control Flow Today Condition codes Control flow structures Next time Procedures Fabián E. Bustamante, Spring 2010 Processor state (ia32, partial) Information about currently
More informationCS 31: Intro to Systems ISAs and Assembly. Kevin Webb Swarthmore College February 9, 2016
CS 31: Intro to Systems ISAs and Assembly Kevin Webb Swarthmore College February 9, 2016 Reading Quiz Overview How to directly interact with hardware Instruction set architecture (ISA) Interface between
More informationSystem Programming and Computer Architecture (Fall 2009)
System Programming and Computer Architecture (Fall 2009) Recitation 2 October 8 th, 2009 Zaheer Chothia Email: zchothia@student.ethz.ch Web: http://n.ethz.ch/~zchothia/ Topics for Today Classroom Exercise
More informationAssembly III: Procedures. Jo, Heeseung
Assembly III: Procedures Jo, Heeseung IA-32 Stack (1) Characteristics Region of memory managed with stack discipline Grows toward lower addresses Register indicates lowest stack address - address of top
More informationCS 31: Intro to Systems ISAs and Assembly. Kevin Webb Swarthmore College September 25, 2018
CS 31: Intro to Systems ISAs and Assembly Kevin Webb Swarthmore College September 25, 2018 Overview How to directly interact with hardware Instruction set architecture (ISA) Interface between programmer
More informationTHEORY OF COMPILATION
Lecture 10 Activation Records THEORY OF COMPILATION EranYahav www.cs.technion.ac.il/~yahave/tocs2011/compilers-lec10.pptx Reference: Dragon 7.1,7.2. MCD 6.3,6.4.2 1 You are here Compiler txt Source Lexical
More informationCMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING PREVIEW SLIDES 16, SPRING 2013
CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING PREVIEW SLIDES 16, SPRING 2013 CONST POINTERS CONST POINTERS 4 ways to declare pointers in combination with const:!! int *ptr! const int *ptr!
More informationCSC 221: Introduction to Programming. Fall 2013
CSC 221: Introduction to Programming Fall 2013 Python data, assignments & turtles Scratch programming review Python & IDLE numbers & expressions variables & assignments strings & concatenation input &
More informationASSEMBLY III: PROCEDURES. Jo, Heeseung
ASSEMBLY III: PROCEDURES Jo, Heeseung IA-32 STACK (1) Characteristics Region of memory managed with stack discipline Grows toward lower addresses Register indicates lowest stack address - address of top
More informationLECTURE 1. Getting Started with Python
LECTURE 1 Getting Started with Python ABOUT PYTHON Development started in the 1980 s by Guido van Rossum. Only became popular in the last decade or so. Python 2.x currently dominates, but Python 3.x is
More informationCMSC 313 Lecture 12 [draft] How C functions pass parameters
CMSC 313 Lecture 12 [draft] How C functions pass parameters UMBC, CMSC313, Richard Chang Last Time Stack Instructions: PUSH, POP PUSH adds an item to the top of the stack POP removes an
More informationCS241 Computer Organization Spring Addresses & Pointers
CS241 Computer Organization Spring 2015 Addresses & Pointers 2-24 2015 Outline! Addresses & Pointers! leal - load effective address! Condition Codes & Jumps! conditional statements: if-then-else! conditional
More informationMachine-level Programming (3)
Machine-level Programming (3) Procedures A: call A call A return Two issues How to return to the correct position? How to pass arguments and return values between callee to caller? 2 Procedure Control
More informationAssembly III: Procedures. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University
Assembly III: Procedures Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu IA-32 (1) Characteristics Region of memory managed with stack discipline
More informationFunction Calls COS 217. Reading: Chapter 4 of Programming From the Ground Up (available online from the course Web site)
Function Calls COS 217 Reading: Chapter 4 of Programming From the Ground Up (available online from the course Web site) 1 Goals of Today s Lecture Finishing introduction to assembly language o EFLAGS register
More informationCOMP 210 Example Question Exam 2 (Solutions at the bottom)
_ Problem 1. COMP 210 Example Question Exam 2 (Solutions at the bottom) This question will test your ability to reconstruct C code from the assembled output. On the opposing page, there is asm code for
More informationCS , Fall 2004 Exam 1
Andrew login ID: Full Name: CS 15-213, Fall 2004 Exam 1 Tuesday October 12, 2004 Instructions: Make sure that your exam is not missing any sheets, then write your full name and Andrew login ID on the front.
More informationProcess Layout and Function Calls
Process Layout and Function Calls CS 6 Spring 07 / 8 Process Layout in Memory Stack grows towards decreasing addresses. is initialized at run-time. Heap grow towards increasing addresses. is initialized
More informationCSC 2400: Computing Systems. X86 Assembly: Function Calls"
CSC 24: Computing Systems X86 Assembly: Function Calls" 1 Lecture Goals! Challenges of supporting functions" Providing information for the called function" Function arguments and local variables" Allowing
More informationRegister Allocation, iii. Bringing in functions & using spilling & coalescing
Register Allocation, iii Bringing in functions & using spilling & coalescing 1 Function Calls ;; f(x) = let y = g(x) ;; in h(y+x) + y*5 (:f (x
More informationx86 assembly CS449 Fall 2017
x86 assembly CS449 Fall 2017 x86 is a CISC CISC (Complex Instruction Set Computer) e.g. x86 Hundreds of (complex) instructions Only a handful of registers RISC (Reduced Instruction Set Computer) e.g. MIPS
More informationCMSC 313 Lecture 12. Project 3 Questions. How C functions pass parameters. UMBC, CMSC313, Richard Chang
Project 3 Questions CMSC 313 Lecture 12 How C functions pass parameters UMBC, CMSC313, Richard Chang Last Time Stack Instructions: PUSH, POP PUSH adds an item to the top of the stack POP
More informationThe course that gives CMU its Zip! Machine-Level Programming III: Procedures Sept. 17, 2002
15-213 The course that gives CMU its Zip! Machine-Level Programming III: Procedures Sept. 17, 2002 Topics IA32 stack discipline Register saving conventions Creating pointers to local variables class07.ppt
More informationWhat is a Compiler? Compiler Construction SMD163. Why Translation is Needed: Know your Target: Lecture 8: Introduction to code generation
Compiler Construction SMD163 Lecture 8: Introduction to code generation Viktor Leijon & Peter Jonsson with slides by Johan Nordlander Contains material generously provided by Mark P. Jones What is a Compiler?
More informationSD314 Outils pour le Big Data
Institut Supérieur de l Aéronautique et de l Espace SD314 Outils pour le Big Data Functional programming in Python Christophe Garion DISC ISAE Christophe Garion SD314 Outils pour le Big Data 1/ 35 License
More informationInstruction Set Architecture
CS:APP Chapter 4 Computer Architecture Instruction Set Architecture Randal E. Bryant Carnegie Mellon University http://csapp.cs.cmu.edu CS:APP Instruction Set Architecture Assembly Language View! Processor
More informationInstruction Set Architecture
CS:APP Chapter 4 Computer Architecture Instruction Set Architecture Randal E. Bryant Carnegie Mellon University http://csapp.cs.cmu.edu CS:APP Instruction Set Architecture Assembly Language View Processor
More informationProcedure Calls. Young W. Lim Mon. Young W. Lim Procedure Calls Mon 1 / 29
Procedure Calls Young W. Lim 2017-08-21 Mon Young W. Lim Procedure Calls 2017-08-21 Mon 1 / 29 Outline 1 Introduction Based on Stack Background Transferring Control Register Usage Conventions Procedure
More information1 /* file cpuid2.s */ 4.asciz "The processor Vendor ID is %s \n" 5.section.bss. 6.lcomm buffer, section.text. 8.globl _start.
1 /* file cpuid2.s */ 2.section.data 3 output: 4.asciz "The processor Vendor ID is %s \n" 5.section.bss 6.lcomm buffer, 12 7.section.text 8.globl _start 9 _start: 10 movl $0, %eax 11 cpuid 12 movl $buffer,
More informationCSC 2400: Computer Systems. Towards the Hardware: Machine-Level Representation of Programs
CSC 2400: Computer Systems Towards the Hardware: Machine-Level Representation of Programs Towards the Hardware High-level language (Java) High-level language (C) assembly language machine language (IA-32)
More information1 Decorators. 2 Descriptors. 3 Static Variables. 4 Anonymous Classes. Sandeep Sadanandan (TU, Munich) Python For Fine Programmers July 13, / 19
1 Decorators 2 Descriptors 3 Static Variables 4 Anonymous Classes Sandeep Sadanandan (TU, Munich) Python For Fine Programmers July 13, 2009 1 / 19 Decorator Pattern In object-oriented programming, the
More informationCS213. Machine-Level Programming III: Procedures
CS213 Machine-Level Programming III: Procedures Topics IA32 stack discipline Register saving conventions Creating pointers to local variables IA32 Region of memory managed with stack discipline Grows toward
More informationCS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 21: Generating Pentium Code 10 March 08
CS412/CS413 Introduction to Compilers Tim Teitelbaum Lecture 21: Generating Pentium Code 10 March 08 CS 412/413 Spring 2008 Introduction to Compilers 1 Simple Code Generation Three-address code makes it
More informationCS61 Section Solutions 3
CS61 Section Solutions 3 (Week of 10/1-10/5) 1. Assembly Operand Specifiers 2. Condition Codes 3. Jumps 4. Control Flow Loops 5. Procedure Calls 1. Assembly Operand Specifiers Q1 Operand Value %eax 0x104
More informationY86 Processor State. Instruction Example. Encoding Registers. Lecture 7A. Computer Architecture I Instruction Set Architecture Assembly Language View
Computer Architecture I Instruction Set Architecture Assembly Language View Processor state Registers, memory, Instructions addl, movl, andl, How instructions are encoded as bytes Layer of Abstraction
More informationTowards the Hardware"
CSC 2400: Computer Systems Towards the Hardware Chapter 2 Towards the Hardware High-level language (Java) High-level language (C) assembly language machine language (IA-32) 1 High-Level Language Make programming
More informationSOFTWARE ARCHITECTURE 5. COMPILER
1 SOFTWARE ARCHITECTURE 5. COMPILER Tatsuya Hagino hagino@sfc.keio.ac.jp slides URL https://vu5.sfc.keio.ac.jp/sa/ 2 Programming Language Programming Language Artificial language to express instructions
More informationAssembly Language Programming - III
Assembly Language Programming - III GDB Debugger Please refer to the handout New GDB commands (power.s) info registers (prints all register values) print/d $eax (prints individual register value. Note
More informationMachine-Level Programming II: Control and Arithmetic
Machine-Level Programming II: Control and Arithmetic CSCI 2400: Computer Architecture Instructor: David Ferry Slides adapted from Bryant & O Hallaron s slides 1 Today Complete addressing mode, address
More informationQuestion 4.2 2: (Solution, p 5) Suppose that the HYMN CPU begins with the following in memory. addr data (translation) LOAD 11110
Questions 1 Question 4.1 1: (Solution, p 5) Define the fetch-execute cycle as it relates to a computer processing a program. Your definition should describe the primary purpose of each phase. Question
More informationCompiler Construction D7011E
Compiler Construction D7011E Lecture 8: Introduction to code generation Viktor Leijon Slides largely by Johan Nordlander with material generously provided by Mark P. Jones. 1 What is a Compiler? Compilers
More informationInstruction Set Architecture
CS:APP Chapter 4 Computer Architecture Instruction Set Architecture Randal E. Bryant adapted by Jason Fritts http://csapp.cs.cmu.edu CS:APP2e Hardware Architecture - using Y86 ISA For learning aspects
More informationCode Generation. Lecture 30
Code Generation Lecture 30 (based on slides by R. Bodik) 11/14/06 Prof. Hilfinger CS164 Lecture 30 1 Lecture Outline Stack machines The MIPS assembly language The x86 assembly language A simple source
More informationCIT Week13 Lecture
CIT 3136 - Week13 Lecture Runtime Environments During execution, allocation must be maintained by the generated code that is compatible with the scope and lifetime rules of the language. Typically there
More information4) C = 96 * B 5) 1 and 3 only 6) 2 and 4 only
Instructions: The following questions use the AT&T (GNU) syntax for x86-32 assembly code, as in the course notes. Submit your answers to these questions to the Curator as OQ05 by the posted due date and
More informationProcess Layout, Function Calls, and the Heap
Process Layout, Function Calls, and the Heap CS 6 Spring 20 Prof. Vern Paxson TAs: Devdatta Akhawe, Mobin Javed, Matthias Vallentin January 9, 20 / 5 2 / 5 Outline Process Layout Function Calls The Heap
More informationComputer Systems Lecture 9
Computer Systems Lecture 9 CPU Registers in x86 CPU status flags EFLAG: The Flag register holds the CPU status flags The status flags are separate bits in EFLAG where information on important conditions
More informationLecture #16: Introduction to Runtime Organization. Last modified: Fri Mar 19 00:17: CS164: Lecture #16 1
Lecture #16: Introduction to Runtime Organization Last modified: Fri Mar 19 00:17:19 2010 CS164: Lecture #16 1 Status Lexical analysis Produces tokens Detects & eliminates illegal tokens Parsing Produces
More informationX86 Addressing Modes Chapter 3" Review: Instructions to Recognize"
X86 Addressing Modes Chapter 3" Review: Instructions to Recognize" 1 Arithmetic Instructions (1)! Two Operand Instructions" ADD Dest, Src Dest = Dest + Src SUB Dest, Src Dest = Dest - Src MUL Dest, Src
More informationASSEMBLY II: CONTROL FLOW. Jo, Heeseung
ASSEMBLY II: CONTROL FLOW Jo, Heeseung IA-32 PROCESSOR STATE Temporary data Location of runtime stack %eax %edx %ecx %ebx %esi %edi %esp %ebp General purpose registers Current stack top Current stack frame
More informationCPSC W Term 2 Problem Set #3 - Solution
1. (a) int gcd(int a, int b) { if (a == b) urn a; else if (a > b) urn gcd(a - b, b); else urn gcd(a, b - a); CPSC 313 06W Term 2 Problem Set #3 - Solution.file "gcdrec.c".globl gcd.type gcd, @function
More information15-213/18-243, Summer 2011 Exam 1 Tuesday, June 28, 2011
Andrew login ID: Full Name: Section: 15-213/18-243, Summer 2011 Exam 1 Tuesday, June 28, 2011 Instructions: Make sure that your exam is not missing any sheets, then write your Andrew login ID, full name,
More informationSistemi Operativi. Lez. 16 Elementi del linguaggio Assembler AT&T
Sistemi Operativi Lez. 16 Elementi del linguaggio Assembler AT&T Data Sizes Three main data sizes Byte (b): 1 byte Word (w): 2 bytes Long (l): 4 bytes Separate assembly-language instructions E.g., addb,
More informationCSC 8400: Computer Systems. Machine-Level Representation of Programs
CSC 8400: Computer Systems Machine-Level Representation of Programs Towards the Hardware High-level language (Java) High-level language (C) assembly language machine language (IA-32) 1 Compilation Stages
More informationControl flow. Condition codes Conditional and unconditional jumps Loops Switch statements
Control flow Condition codes Conditional and unconditional jumps Loops Switch statements 1 Conditionals and Control Flow Familiar C constructs l l l l l l if else while do while for break continue Two
More informationAssembly II: Control Flow. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University
Assembly II: Control Flow Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu IA-32 Processor State %eax %edx Temporary data Location of runtime stack
More informationStack Discipline Jan. 19, 2018
15-410 An Experience Like No Other Discipline Jan. 19, 2018 Dave Eckhardt Brian Railing Slides originally stolen from 15-213 1 15-410, S 18 Synchronization Registration The wait list will probably be done
More informationTHEORY OF COMPILATION
Lecture 10 Code Generation THEORY OF COMPILATION EranYahav Reference: Dragon 8. MCD 4.2.4 1 You are here Compiler txt Source Lexical Analysis Syntax Analysis Parsing Semantic Analysis Inter. Rep. (IR)
More informationIntel assembly language using gcc
QOTD Intel assembly language using gcc Assembly language programming is difficult. Make no mistake about that. It is not for wimps and weaklings. - Tanenbaum s 6th, page 519 These notes are a supplement
More informationCompilation /15a Lecture 7. Activation Records Noam Rinetzky
Compilation 0368-3133 2014/15a Lecture 7 Activation Records Noam Rinetzky 1 Code generation for procedure calls (+ a few words on the runtime system) 2 Code generation for procedure calls Compile time
More informationCS241 Computer Organization Spring 2015 IA
CS241 Computer Organization Spring 2015 IA-32 2-10 2015 Outline! Review HW#3 and Quiz#1! More on Assembly (IA32) move instruction (mov) memory address computation arithmetic & logic instructions (add,
More informationMachine-Level Programming II: Arithmetic & Control. Complete Memory Addressing Modes
Machine-Level Programming II: Arithmetic & Control CS-281: Introduction to Computer Systems Instructor: Thomas C. Bressoud 1 Complete Memory Addressing Modes Most General Form D(Rb,Ri,S)Mem[Reg[Rb]+S*Reg[Ri]+
More informationCS558 Programming Languages
CS558 Programming Languages Winter 2017 Lecture 1a Andrew Tolmach Portland State University 1994-2017 1 What programming languages do you know? Some historically interesting and/or currently visible languages:
More informationCredits to Randy Bryant & Dave O Hallaron
Mellon Machine Level Programming II: Arithmetic & Control Lecture 4, March 10, 2011 Alexandre David Credits to Randy Bryant & Dave O Hallaron from Carnegie Mellon 1 Today Complete addressing mode, address
More informationMachine-Level Programming III: Procedures
Machine-Level Programming III: Procedures IA32 Region of memory managed with stack discipline Grows toward lower addresses Register indicates lowest stack address address of top element Bottom Increasing
More informationRegion of memory managed with stack discipline Grows toward lower addresses. Register %esp contains lowest stack address = address of top element
Machine Representa/on of Programs: Procedures Instructors: Sanjeev Se(a 1 IA32 Stack Region of memory managed with stack discipline Grows toward lower addresses Stack BoGom Increasing Addresses Register
More informationX86 Assembly -Procedure II:1
X86 Assembly -Procedure II:1 IA32 Object Code Setup Label.L61 becomes address 0x8048630 Label.L62 becomes address 0x80488dc Assembly Code switch_eg:... ja.l61 # if > goto default jmp *.L62(,%edx,4) # goto
More informationMachine Level Programming II: Arithmetic &Control
Machine Level Programming II: Arithmetic &Control Arithmetic operations Control: Condition codes Conditional branches Loops Switch Kai Shen 1 2 Some Arithmetic Operations Two Operand Instructions: Format
More informationLearning R via Python...or the other way around
Learning R via Python...or the other way around Dept. of Politics - NYU January 7, 2010 What We ll Cover Brief review of Python The Zen of Python How are R and Python the same, and how are they different
More informationCS241 Computer Organization Spring Loops & Arrays
CS241 Computer Organization Spring 2015 Loops & Arrays 2-26 2015 Outline! Loops C loops: while, for, do-while Translation to jump to middle! Arrays Read: CS:APP2 Chapter 3, sections 3.6 3.7 IA32 Overview
More informationChapter 3 Machine-Level Programming II Control Flow
Chapter 3 Machine-Level Programming II Control Flow Topics Condition Codes Setting Testing Control Flow If-then-else Varieties of Loops Switch Statements Condition Codes Single Bit Registers CF Carry Flag
More informationMachine-Level Programming II: Arithmetic & Control /18-243: Introduction to Computer Systems 6th Lecture, 5 June 2012
n Mello Machine-Level Programming II: Arithmetic & Control 15-213/18-243: Introduction to Computer Systems 6th Lecture, 5 June 2012 Instructors: Gregory Kesden The course that gives CMU its Zip! Last Time:
More informationMachine Representa/on of Programs: Control Flow cont d. Previous lecture. Do- While loop. While- Do loop CS Instructors: Sanjeev Se(a
Machine Representa/on of Programs: Control Flow cont d Instructors: Sanjeev Se(a 1 Previous lecture Do- While loop C Code Goto Version While- Do loop do while (Test); if (Test) goto loop Do- While Version
More informationCS 31: Intro to Systems ISAs and Assembly. Martin Gagné Swarthmore College February 7, 2017
CS 31: Intro to Systems ISAs and Assembly Martin Gagné Swarthmore College February 7, 2017 ANNOUNCEMENT All labs will meet in SCI 252 (the robot lab) tomorrow. Overview How to directly interact with hardware
More informationFinal exam. Scores. Fall term 2012 KAIST EE209 Programming Structures for EE. Thursday Dec 20, Student's name: Student ID:
Fall term 2012 KAIST EE209 Programming Structures for EE Final exam Thursday Dec 20, 2012 Student's name: Student ID: The exam is closed book and notes. Read the questions carefully and focus your answers
More informationCode Generation Introduction
Code Generation Introduction i = 0 LF w h i l e i=0 while (i < 10) { a[i] = 7*i+3 i = i + 1 lexer i = 0 while ( i < 10 ) source code (e.g. Scala, Java,C) easy to write Compiler (scalac, gcc) parser type
More informationFunction Call Convention
Function Call Convention Compass Security Schweiz AG Werkstrasse 20 Postfach 2038 CH-8645 Jona Tel +41 55 214 41 60 Fax +41 55 214 41 61 team@csnc.ch www.csnc.ch Content Intel Architecture Memory Layout
More informationCSE 582 Autumn 2002 Exam Sample Solution
Question 1. (10 points) Regular expressions. Describe the set of strings that are generated by the each of the following regular expressions. a) (a (bc)* d)+ One or more of the string a or the string d
More informationImplementing Threads. Operating Systems In Depth II 1 Copyright 2018 Thomas W. Doeppner. All rights reserved.
Implementing Threads Operating Systems In Depth II 1 Copyright 2018 Thomas W Doeppner All rights reserved The Unix Address Space stack dynamic bss data text Operating Systems In Depth II 2 Copyright 2018
More informationAssembly Language for Intel-Based Computers, 4 th Edition
Assembly Language for Intel-Based Computers, 4 th Edition Kip R Irvine Chapter 5: Procedures Lecture 19: Procedures Procedure s parameters Slides prepared by Kip R Irvine Revision date: 08/22/2002 Modified
More informationProcedure Calls. Young W. Lim Sat. Young W. Lim Procedure Calls Sat 1 / 27
Procedure Calls Young W. Lim 2016-11-05 Sat Young W. Lim Procedure Calls 2016-11-05 Sat 1 / 27 Outline 1 Introduction References Stack Background Transferring Control Register Usage Conventions Procedure
More informationInstruction Set Architecture
CISC 360 Instruction Set Architecture Michela Taufer October 9, 2008 Powerpoint Lecture Notes for Computer Systems: A Programmer's Perspective, R. Bryant and D. O'Hallaron, Prentice Hall, 2003 Chapter
More informationEECE.3170: Microprocessor Systems Design I Summer 2017 Homework 4 Solution
1. (40 points) Write the following subroutine in x86 assembly: Recall that: int f(int v1, int v2, int v3) { int x = v1 + v2; urn (x + v3) * (x v3); Subroutine arguments are passed on the stack, and can
More informationCISC 360 Instruction Set Architecture
CISC 360 Instruction Set Architecture Michela Taufer October 9, 2008 Powerpoint Lecture Notes for Computer Systems: A Programmer's Perspective, R. Bryant and D. O'Hallaron, Prentice Hall, 2003 Chapter
More informationSoftware Lesson 2 Outline
Software Lesson 2 Outline 1. Software Lesson 2 Outline 2. Languages 3. Ingredients of a Language 4. Kinds of Languages 5. Natural Languages #1 6. Natural Languages #2 7. Natural Languages #3 8. Natural
More informationLecture Outline. Code Generation. Lecture 30. Example of a Stack Machine Program. Stack Machines
Lecture Outline Code Generation Lecture 30 (based on slides by R. Bodik) Stack machines The MIPS assembly language The x86 assembly language A simple source language Stack-machine implementation of the
More informationCS 33: Week 3 Discussion. x86 Assembly (v1.0) Section 1G
CS 33: Week 3 Discussion x86 Assembly (v1.0) Section 1G Announcements - HW2 due Sunday - MT1 this Thursday! - Lab2 out Info Name: Eric Kim (Section 1G, 2-4 PM, BH 5419) Office Hours (Boelter 2432) - Wed
More information