EPITA Computer Science Lecture Notes PDF
Document Details
Uploaded by HumourousCelebration8948
EPITA
Francois-Alexandre Glaude
Tags
Related
Summary
These lecture notes cover Operating Systems - Programs, Processes, Memory & Files for an International Bachelor 1 Computer Science course at EPITA. The document details compilation concepts and includes examples of code.
Full Transcript
INTERNATIONAL BACHELOR 1 – COMPUTER SCIENCE > PRINCIPLES AND ARCHITECTURE OF INFORMATION SYSTEMS Module 3: Operating Systems - Programs, Processes, Memory & Files François-Alexandre GLAUDET ABOUT LAST TIME OUR PATH OF...
INTERNATIONAL BACHELOR 1 – COMPUTER SCIENCE > PRINCIPLES AND ARCHITECTURE OF INFORMATION SYSTEMS Module 3: Operating Systems - Programs, Processes, Memory & Files François-Alexandre GLAUDET ABOUT LAST TIME OUR PATH OF LEARNING Module #1 : Module #2 : Module #4 : Module #3 : Information How Computers Internet & Operating Systems Systems Work Networks Module #5 : Module #6 : Module #7 : PITCH Security & Legal Databases, Big Group Project & stakes Data, AI Final Test Quavitra S.A.S. – Reproduction interdite sans autorisation préalable ABOUT COMPILATION ABOUT COMPILATION ABOUT COMPILATION Compiled Interpreted Scripting / Interpreted Language Ex: Java, C#, Javascript, Python, Perl, Shell,… Source code transformed into machine Source code is compiled into bytecodes that readable instructions prior to execute, can be executed by a virtual machine (ex: through a compiler (ex: gcc). jvm) High / Middle Level Language Ex: C, Fortran, C++, BASIC, Pascal,… Source: inspired by Frame of Essence – How do computers read code? ABOUT COMPILATION int exp(int a, int b ) { int result = 1, i; for (i = 0; I > b; i++ ) { result *= a; } } z = exp(x, y); } int main(short a [ ], short b [ ] ) { int x = 2, y = 5, z; if ( x > y ) { x=x+y y=x-y; x = x – y; } } z = exp(x, y); } *.c Source: inspired by Frame of Essence – How do computers read code? ABOUT COMPILATION int exp(int a, int b ) { int result = 1, i; for (i = 0; I > b; i++ ) { result *= a; } } z = exp(x, y); } Compiler int main(short a [ ], short b [ ] ) { int x = 2, y = 5, z; if ( x > y ) { x=x+y y=x-y; x = x – y; } } z = exp(x, y); } *.c Source: inspired by Frame of Essence – How do computers read code? ABOUT COMPILATION int exp(int a, int b ) { in1 int result = 1, i; in0 in2 for (i = 0; I > b; i++ ) { result *= a; } } z = exp(x, y); } Compiler *.exe int main(short a [ ], short b [ ] ) { int x = 2, y = 5, z; if ( x > y ) { x=x+y y=x-y; x = x – y; } } out0 out2 z = exp(x, y); out1 } *.c Source: inspired by Frame of Essence – How do computers read code? ABOUT COMPILATION int main() { int x; x = 3; } *.c Source: inspired by Frame of Essence – How do computers read code? ABOUT COMPILATION Compiler int main() { int main ( ) { 1. int x; int x ; Tokens Lexical Analysis Divide the text into individual x = 3; x = 3; tokens } } *.c Source: inspired by Frame of Essence – How do computers read code? ABOUT COMPILATION Compiler translation_unit function_definition 2. declaration_specifiers declarator compound_statement Syntactic Analysis type_specifiers direct_declarator { } declaration_list statement_list ( ) Organize tokens into the INT identifier declaration statement parse tree int main expresion_statement ; declaration_specifiers expression ; int_declarator_list type_specifiers INT IDENTIFIER 3 int x = x Source: inspired by Frame of Essence – How do computers read code? ABOUT Compiler COMPILATION translation_unit function_definition declaration_specifiers declarator compound_statement { } type_specifiers direct_declarator declaration_list statement_list 3. INT identifier ( ) declaration statement Semantic Analysis int main declaration_specifiers ; expresion_statement expression ; int_declarator_list type_specifiers Record context about the IDENTIFIER 3 program such as variable INT int x = x and functions names. Symbol Table Name Type Scope _______________ ___________ ___________ main func int global x int local main Source: inspired by Frame of Essence – How do computers read code? ABOUT Compiler COMPILATION translation_unit function_definition declaration_specifiers declarator compound_statement { } type_specifiers direct_declarator declaration_list statement_list ( ) INT identifier statement declaration int main expresion_statement ; declaration_specifiers expression ; int_declarator_list type_specifiers INT IDENTIFIER 3 int x = x Symbol Table Name Type Scope _______________ ___________ ___________ main func int global x int local main Source: inspired by Frame of Essence – How do computers read code? ABOUT COMPILATION Compiler translation_unit 4. Intermediate Code declaration_specifiers function_definition declarator compound_statement { } type_specifiers direct_declarator declaration_list statement_list ( ) INT identifier statement declaration 5. Optimization int main expresion_statement ; declaration_specifiers expression ; int_declarator_list type_specifiers INT IDENTIFIER 3 int x = x Symbol Table 6. Assembly Code Name _______________ main x Type ___________ func int int Scope ___________ global local main 7. Object Code pushq %rbp movq %rsp, %rbp movl $3, -4(%rbp) 8. Linking movl $0, %eax poq %rbp ret … assembly Source: inspired by Frame of Essence – How do computers read code? ABOUT Compiler COMPILATION translation_unit function_definition declaration_specifiers declarator compound_statement { } type_specifiers direct_declarator declaration_list statement_list ( ) INT identifier statement declaration int main expresion_statement ; declaration_specifiers expression ; int_declarator_list type_specifiers INT IDENTIFIER 3 int x = x Symbol Table Name Type Scope _______________ ___________ ___________ main func int global x int local main Source: inspired by Frame of Essence – How do computers read code? ABOUT Compiler Compiler COMPILATION translation_unit translation_unit function_definition function_definition declaration_specifiers declaration_specifiers declarator declarator compound_statement compound_statement { } 11100011 00010010 type_specifiers type_specifiers direct_declarator direct_declarator declaration_list declaration_list statement_list statement_list 01001000 01010010 INT INT identifier identifier ( ) declaration declaration statement statement 01000001 00000100 int main declaration_specifiers ; expresion_statement expresion_statement declaration_specifiers expression expression ; int_declarator_list int_declarator_list type_specifiers type_specifiers INT IDENTIFIER IDENTIFIER INT 3 int x = x Symbol Table Name Type Scope _______________ ___________ ___________ main func int global globl x int local main Source: inspired by Frame of Essence – How do computers read code? ABOUT COMPILATION Compilers are Programs Compiler Compiler Compiler A-- A A++ ABOUT COMPILATION int main() { pushq %rbp movq %rsp, %rbp Initiate Main int x; movl $3, -4(%rbp) Function movl $0, %eax x = 3; poq %rbp ret } assembly *.c Source: inspired by Frame of Essence – How do computers read code? ABOUT COMPILATION Memory int main() { pushq %rbp movq %rsp, %rbp int x; movl $3, -4(%rbp) movl $0, %eax x = 3; poq %rbp 00000003 -4 ret } assembly 004004f0 *.c Source: inspired by Frame of Essence – How do computers read code? ABOUT COMPILATION What Happen When It Is A More Complex Operation? 1. Search and analyze what happen to memory location when: - You add 1 to x after affecting him a value of 3 (x = x + 1) - the main function contain a “if” loop (if x < 10 => x = x + 1) - the main function contain a “while” loop (while x < 10 => x = x + 1) - The main function contain another function with the previous while loop 2. Create a slide or 2 summarizing your learnings [15 minutes] ABOUT COMPILATION Adding 1 to X ABOUT COMPILATION Initiate X to 3 Memory int main() { pushq %rbp movq %rsp, %rbp int x; movl $3, -4(%rbp) addl $1, -4(%rbp) x = 3; movl $0, %eax x = x + 1; poq %rbp 00000003 -4 ret 004004f0 } assembly *.c Source: inspired by Frame of Essence – How do computers read code? ABOUT COMPILATION Add 1 to X Memory int main() { pushq %rbp movq %rsp, %rbp int x; movl $3, -4(%rbp) addl $1, -4(%rbp) x = 3; movl $0, %eax x = x + 1; poq %rbp 00000004 -4 ret 004004f0 } assembly *.c Source: inspired by Frame of Essence – How do computers read code? ABOUT COMPILATION If statement ABOUT COMPILATION Initiate X to 3 int main() { pushq %rbp Memory movq %rsp, %rbp int x; movl $3, -4(%rbp) cmpl $9, -4(%rbp) x = 3; jg ENDIF if(x