Get To Know Your Compiler

Slides:



Advertisements
Similar presentations
University of Washington Procedures and Stacks II The Hardware/Software Interface CSE351 Winter 2013.
Advertisements

Machine/Assembler Language Putting It All Together Noah Mendelsohn Tufts University Web:
%rax %eax %rbx %ebx %rdx %edx %rcx %ecx %rsi %esi %rdi %edi %rbp %ebp %rsp %esp %r8 %r8d %r9 %r9d %r11 %r11d %r10 %r10d %r12 %r12d %r13 %r13d.
Recitation: Bomb Lab June 5, 2015 Dipayan Bhattacharya.
64-Bit Architectures Topics 64-bit data New registers and instructions Calling conventions CS 105 “Tour of the Black Holes of Computing!”
Machine-Level Programming: X86-64 Topics Registers Stack Function Calls Local Storage X86-64.ppt CS 105 Tour of Black Holes of Computing.
Machine-Level Programming III: Procedures Topics IA32 stack discipline Register-saving conventions Creating pointers to local variables CS 105 “Tour of.
Carnegie Mellon Recitation: Bomb Lab 21 Sep 2015 Monil Shah, Shelton D’Souza.
Carnegie Mellon 1 Machine-Level Programming I: Basics Slides based on from those of Bryant and O’Hallaron.
Carnegie Mellon 1 Odds and Ends Intro to x86-64 Memory Layout.
1 Carnegie Mellon Assembly and Bomb Lab : Introduction to Computer Systems Recitation 4, Sept. 17, 2012.
Chapter 2 Parts of a Computer System. 2.1 PC Hardware: Memory.
Reminder Bomb lab is due tomorrow! Attack lab is released tomorrow!!
X86_64 programming Tutorial #1 CPSC 261. X86_64 An extension of the IA32 (often called x86 – originated in the Intel 8086 processor) instruction set to.
1 Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Carnegie Mellon Machine-Level Programming II: Control Carnegie Mellon.
Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Carnegie Mellon Instructor: San Skulrattanakulchai Machine-Level Programming.
Information Security - 2. CISC Vs RISC X86 is CISC while ARM is RISC CISC is Compiler’s heaven while RISC is Architecture’s heaven Orthogonal ISA in RISC.
Assembly Language Alan L. Cox Alan L. CoxAssembly2 Why Learn Assembly Language? You’ll probably never write a program in assembly  Compilers.
Spring 2016Assembly Review Roadmap 1 car *c = malloc(sizeof(car)); c->miles = 100; c->gals = 17; float mpg = get_mpg(c); free(c); Car c = new Car(); c.setMiles(100);
Instruction Set Architecture
Credits and Disclaimers
Machine-Level Programming I: Basics
Credits and Disclaimers
CSCE 212 Computer Architecture
Assembly Programming II CSE 351 Spring 2017
Instructor: Your TA(s)
More GDB, Intro to x86 Calling Conventions, Control Flow, & Lab 2
Assembly Programming III CSE 410 Winter 2017
Assembly Programming III CSE 351 Spring 2017
Low level Programming.
Introduction to Computer Systems
Machine-Level Programming III: Procedures
Recitation: Attack Lab
x86 Programming II CSE 351 Autumn 2016
x86-64 Programming II CSE 351 Autumn 2017
x86-64 Programming II CSE 351 Winter 2018
Machine-Level Programming III: Procedures /18-213/14-513/15-513: Introduction to Computer Systems 7th Lecture, September 18, 2018.
Carnegie Mellon Machine-Level Programming III: Procedures : Introduction to Computer Systems October 22, 2015 Instructor: Rabi Mahapatra Authors:
Processor Architecture: The Y86-64 Instruction Set Architecture
Carnegie Mellon Wrap-up of Machine-Level Programming II: Control : Introduction to Computer Systems Sept. 18, 2018.
CSE 351 Section 10 The END…Almost 3/7/12
Processor Architecture: The Y86-64 Instruction Set Architecture
Assembly Programming II CSE 410 Winter 2017
x86-64 Programming I CSE 351 Autumn 2017
Roadmap C: Java: Assembly language: OS: Machine code: Computer system:
Ithaca College Machine-Level Programming VII: Procedures Comp 21000: Introduction to Computer Systems & Assembly Lang Spring 2017.
x86-64 Programming I CSE 351 Winter 2018
Oct 15, 2018 Instructor: Your TA(s) 1.
University of Gujrat Department of Computer Science
Machine-Level Programming III: Arithmetic Comp 21000: Introduction to Computer Organization & Systems March 2017 Systems book chapter 3* * Modified slides.
x86-64 Programming I CSE 351 Winter 2018
Computer Architecture and System Programming Laboratory
Reverse Engineering for CTFs
x86-64 Programming II CSE 351 Autumn 2018
Ithaca College Machine-Level Programming VII: Procedures Comp 21000: Introduction to Computer Systems & Assembly Lang Spring 2017.
Machine-Level Programming III: Arithmetic Comp 21000: Introduction to Computer Organization & Systems March 2017 Systems book chapter 3* * Modified slides.
Machine-Level Programming II: Basics Comp 21000: Introduction to Computer Organization & Systems Spring 2016 Instructor: John Barr * Modified slides.
Carnegie Mellon Ithaca College
Carnegie Mellon Ithaca College
CS201- Lecture 8 IA32 Flow Control
Machine-Level Programming VIII: Data Comp 21000: Introduction to Computer Systems & Assembly Lang Spring 2017 Systems book chapter 3* * Modified slides.
Ithaca College Machine-Level Programming VII: Procedures Comp 21000: Introduction to Computer Systems & Assembly Lang Spring 2017.
Credits and Disclaimers
Credits and Disclaimers
Credits and Disclaimers
Visual Studio x64 C Compiler function entrance code
Computer Architecture and System Programming Laboratory
CS201- Lecture 7 IA32 Data Access and Operations Part II
Instructor: Your TA(s)
Low level Programming.
Presentation transcript:

Get To Know Your Compiler Inspired by Matt Godbolt

Compilation Stages Preprocessor Compiler Linker Run preprocessor directives –E for clang Compiler Compile the preprocessed source code -S Generate Assembly -c Generate Object Code Linker Generate executable from object files

Does it matter?

X86 Assembly Registers rax, rbx, rcx, rdx, rsp, rbp, rsi, rdi, r8-r15 xmm0-xmm15 rdi, rsi, rdx … arguments rax is the return value

Register Details

Instructions op is call, ret, add, sub, cmp… dest, src is register or memory reference [base + reg1 + reg2 (1, 2, 4, or 8) ]

Instruction Examples

Summary Register: rax, rbx, rcx … Size: rax, eax, ax .. Params: rdi, rsi, rdx, rcx … Result: rax Format: op dest, src dest and src are registers or memory

So Does it matter?

Compiler Explorer Godbolt.org

What is going on?

Multiplication

Fancy Multiplication

Division

Summation int sumTo(int x) { int sum = 0; for( int i = 0; i <= x; ++i ) { sum += i; } return sum; What is the runtime? A) O(1) B) O(x) C) O(x^2) D) What on earth is big O?

Sum(X) from CS 173 𝑥≡ 𝑥 𝑥+1 2 ≡𝑥+ 𝑥(𝑥−1) 2

The compiler is your friend