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);

Slides:



Advertisements
Similar presentations
Machine/Assembler Language Putting It All Together Noah Mendelsohn Tufts University Web:
Advertisements

Instruction Set Architectures
C Prog. To Object Code text text binary binary Code in files p1.c p2.c
Carnegie Mellon 1 Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Machine-Level Programming I: Basics Sep. 15, 2015.
Machine/Assembler Language Control Flow & Compiling Function Calls Noah Mendelsohn Tufts University Web:
University of Washington 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);
University of Washington 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);
Machine-Level Programming III: Procedures Topics IA32 stack discipline Register-saving conventions Creating pointers to local variables CS 105 “Tour of.
Carnegie Mellon 1 Machine-Level Programming I: Basics Slides based on from those of Bryant and O’Hallaron.
University of Washington Basics of Machine Programming The Hardware/Software Interface CSE351 Winter 2013.
University of Washington x86 Programming I The Hardware/Software Interface CSE351 Winter 2013.
Machine/Assembler Language Control Flow & Compiling Function Calls Noah Mendelsohn Tufts University Web:
University of Washington Exceptional Control Flow The Hardware/Software Interface CSE351 Winter 2013.
Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Carnegie Mellon Instructor: San Skulrattanakulchai Machine-Level Programming.
University of Washington Today Lab1, how is it going?  Now due on Sunday HW 1 out! (Integer, FP, …) Luis out of town Monday (no class)  Spend the time.
1 Machine-Level Programming V: Control: loops Comp 21000: Introduction to Computer Organization & Systems March 2016 Systems book chapter 3* * Modified.
University of Washington 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);
Spring 2016Machine Code & C 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);
Today: Machine Programming I: Basics
Machine-Level Programming I: Basics
Instruction Set Architecture
Credits and Disclaimers
Machine-Level Programming I: Basics
Assembly Programming I CSE 351 Spring 2017
Machine-Level Programming I:
Credits and Disclaimers
CSCE 212 Computer Architecture
Final exam: Wednesday, March 20, 2:30pm
Arrays CSE 351 Spring 2017 Instructor: Ruth Anderson
Roadmap C: Java: Assembly language: OS: Machine code: Computer system:
Roadmap C: Java: Assembly language: OS: Machine code: Computer system:
Procedures & Executables CSE 351 Spring 2017
Machine-Level Programming III: Procedures
Procedures & The Stack Announcements Lab 1 graded HW 2 out
Switch & Procedures & The Stack I CSE 351 Winter 2017
Machine-Level Programming 1 Introduction
x86-64 Programming III & The Stack CSE 351 Winter 2018
Assembly Programming IV CSE 351 Spring 2017
x86-64 Programming III & The Stack CSE 351 Winter 2018
Machine-Level Programming III: Procedures /18-213/14-513/15-513: Introduction to Computer Systems 7th Lecture, September 18, 2018.
Procedures & The Stack I CSE 351 Autumn 2016
Arrays CSE 351 Winter
Lecture 5 Machine Programming
Carnegie Mellon Machine-Level Programming III: Procedures : Introduction to Computer Systems October 22, 2015 Instructor: Rabi Mahapatra Authors:
Procedures & Executables CSE 351 Autumn 2017
Roadmap C: Java: Assembly language: OS: Machine code: Computer system:
C Prog. To Object Code text text binary binary Code in files p1.c p2.c
Roadmap C: Java: Assembly language: OS: Machine code: Computer system:
Machine-Level Programming V: Control: loops Comp 21000: Introduction to Computer Organization & Systems Systems book chapter 3* * Modified slides from.
x86-64 Programming III & The Stack CSE 351 Autumn 2017
Structs and Alignment CSE 410 Winter 2017
Authors: Randal E. Bryant and David R. O’Hallaron
Arrays CSE 351 Winter 2018 Instructor: Mark Wyse Teaching Assistants:
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.
Structs & Alignment CSE 351 Autumn 2018
Executables & Arrays CSE 351 Autumn 2018
Machine-Level Programming I: Basics Comp 21000: Introduction to Computer Organization & Systems Instructor: John Barr * Modified slides from the book.
Ithaca College Machine-Level Programming VII: Procedures Comp 21000: Introduction to Computer Systems & Assembly Lang Spring 2017.
Machine-Level Programming II: Basics Comp 21000: Introduction to Computer Organization & Systems Instructor: John Barr * Modified slides from the book.
Machine-Level Programming I: Basics
Machine-Level Programming I: Basics Comp 21000: Introduction to Computer Organization & Systems Instructor: John Barr * Modified slides from the book.
Machine-Level Programming V: Control: loops Comp 21000: Introduction to Computer Organization & Systems Systems book chapter 3* * Modified slides from.
Loops, Switches, Intro to Stack & Procedures CSE 351 Winter 2019
Ithaca College Machine-Level Programming VII: Procedures Comp 21000: Introduction to Computer Systems & Assembly Lang Spring 2017.
Lecture 5 Machine Programming
Credits and Disclaimers
Credits and Disclaimers
Computer Architecture and System Programming Laboratory
Assembly Programming I CSE 351 Spring 2017
Presentation transcript:

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); c.setGals(17); float mpg = c.getMPG(); get_mpg: pushq %rbp movq %rsp, %rbp... popq %rbp ret Java: C: Assembly language: Machine code: Computer system: OS: Memory & data Integers & floats Machine code & C x86 assembly Procedures & stacks Arrays & structs Memory & caches Processes Virtual memory Memory allocation Java vs. C

Spring 2016Assembly Review CPU Assembly Programmer’s View Programmer-Visible State  PC: Program counter  Address of next instruction  Called instruction pointer (%rip) on x86-64  Named registers  Heavily used program data  Together, called “register file”  Condition codes  Store status information about most recent arithmetic operation  Used for conditional branching PC Registers Memory Code Data Stack Addresses Data Instructions Condition Codes 2  Memory  Byte addressable array  Code and user data  Includes Stack (for supporting procedures, we’ll come back to that)

Spring 2016Assembly Review x86-64 Instructions Data movement  mov, movs, movz,... Arithmetic  add, sub, shl, sar, lea,... Control flow  cmp, test, j_, set_,... Stack/procedures  push, pop, call, ret,...

Spring 2016Assembly Review text binary Compiler (gcc –Og -S) Assembler (gcc or as) Linker (gcc or ld) C program (p1.c p2.c) Asm program (p1.s p2.s) Object program (p1.o p2.o) Executable program (p) Static libraries (.a) Turning C into Object Code Code in files p1.c p2.c Compile with command: gcc -Og p1.c p2.c -o p  Use basic optimizations (-Og) [New to recent versions of GCC]  Put resulting machine code in file p 4

Spring 2016Assembly Review Machine Instruction Example C Code  Store value t where dest points Assembly  Move 8-byte value to memory  Quad words in x86-64 parlance  Operands: t:Register%rsi dest:Register%rdx *dest: MemoryM[%rdx] Object Code  3-byte instruction  Stored at address 0x40059e 5 *dest = t; movq %rsi, (%rdx) 0x400539:

Spring 2016Assembly Review Assembling 6 Assembly has labels. pcount_r: movl $0, %eax testq %rdi, %rdi je.L6 pushq %rbx movq %rdi, %rbx shrq %rdi call pcount_r andl $1, %ebx addq %rbx, %rax popq %rbx.L6: rep ret Executable has addresses f6 : 4004f6: b mov $0x0,%eax 4004fb: ff test %rdi,%rdi 4004fe: je : 53 push %rbx : fb mov %rdi,%rbx : 48 d1 ef shr %rdi : e8 ea ff ff ff callq 4004f c: 83 e3 01 and $0x1,%ebx 40050f: d8 add %rbx,%rax : 5b pop %rbx : f3 c3 repz retq gcc -S pcount.c gcc -g pcount.c –o pcount objdump -d pcount assembler

Spring 2016Assembly Review A Picture of Memory (64-bit view) A “64-bit (8-byte) word-aligned” view of memory:  In this type of picture, each row is composed of 8 bytes  Each cell is a byte  A 64-bit pointer will fit on one row 7 0x040x050x060x07 0x0D0x0E0x0F 0x0C 0x00 0x08 0x10 0x18 0x20 0x28 0x30 0x38 0x40 0x48 (note hex addresses) 0x000x010x020x03 0x090x0A0x0B 0x08

Spring 2016Assembly Review A Picture of Memory (64-bit view) f6 : 4004f6: b mov $0x0,%eax 4004fb: ff test %rdi,%rdi 4004fe: je : 53 push %rbx : fb mov %rdi,%rbx : 48 d1 ef shr %rdi : e8 ea ff ff ff callq 4004f c: 83 e3 01 and $0x1,%ebx 40050f: d8 add %rbx,%rax : 5b pop %rbx : f3 c3 repz retq 0|81|92|a3|b4|c5|d6|e7|f 0x00 0x08 0x10... b8000x4004f ff74130x4004f fb48d1efe80x eaff 83e301480x d85bf3c30x Just For Fun This call actually uses a relative address: ea ff ff ff = -22 (little endian)