CPEG421/621 Tutorial
|
|
- Joan Barrett
- 6 years ago
- Views:
Transcription
1 CPEG421/621 Tutorial
2 Compiler data representation system call interface calling convention Assembler object file format object code model Linker program initialization exception handling relocation model Loader 4/2/2012 Juergen Ributzka 2
3 ia32 ia64 8 x 32bit General Purpose Registers 16 x 64bit General Purpose Registers 6 x 16bit Segment Registers 6 x 16bit Segment Registers 8 x 80bit Floating-Point Registers 8 x 80bit Floating-Point Registers 8 x 64bit MMX Registers 8 x 64bit MMX Registers 8 x 128bit XMM Registers 16 x 128bit XMM Registers 32bit address space 64bit address space 4/2/2012 Juergen Ributzka 5
4 Data representation Specifies the size and alignment of the different data types Calling Convention Specifies how to pass arguments to a function Register Convention Specifies who has to save and restore the registers 4/2/2012 Juergen Ributzka 6
5 32 bit 64 bit Type Size Alignment Size Alignment _Bool char Short int enum long long long pointer float double long double /2/2012 Juergen Ributzka 7
6 struct { char c; }; c 0 Size: 1 byte Alignment: 1 byte 4/2/2012 Juergen Ributzka 8
7 struct { char a; short b; }; b 2 pad 1 a 0 Size: 4 byte Alignment: 2 byte 4/2/2012 Juergen Ributzka 9
8 struct { char a; char b; short c; long d; }; c Size: 8 byte Alignment: 4 byte ia32 ABI 2 d b 1 a 0 4 4/2/2012 Juergen Ributzka 10
9 struct { char a; char b; short c; long d; }; c Size: 16 byte Alignment: 8 byte ia64 ABI 2 pad d d b 1 a /2/2012 Juergen Ributzka 11
10 struct { char a; double b; short c; }; pad pad Size: 16 byte Alignment: 4 byte ia32 ABI b b 14 1 c a /2/2012 Juergen Ributzka 12
11 struct { char a; double b; short c; }; pad ia64 ABI pad pad b b 18 1 c a pad 20 Size: 24 byte Alignment: 8 byte 4/2/2012 Juergen Ributzka 13
12 union { char a; short b; int c; }; pad pad 2 Size: 4 byte Alignment: 4 byte c 1 b a /2/2012 Juergen Ributzka 14
13 struct { short a:5; int b:6; int c:7; }; 31 pad 1817 Size: 4 byte Alignment: 4 byte c 1110 b 5 4 a 0 0 4/2/2012 Juergen Ributzka 15
14 struct { short a:9; int b:9; char c; short d:9; short e:9; char f; }; 3 c 23 pad 1817 b 6 15 pad 9 8 e 0 pad 15 pad Size: 12 byte Alignment: 4 byte a d c /2/2012 Juergen Ributzka 16
15 struct { char a; int :0; char b; short :9; char c; char :0; }; 15 pad 9 8 :0 :9 6 0 Size: 9 byte Alignment: 1 byte 1 pad 5 a b c /2/2012 Juergen Ributzka 17
16 Caller The calling function Callee The called function Caller Saved Registers Registers that are not preserved during a function call and need to be saved by the caller Callee Saved Registers Registers that are preserved during a function call and don t need to be saved by the caller. The callee needs to save and restore them. 4/2/2012 Juergen Ributzka 18
17 Register Description Save site %eax Return value Caller %edx Dividend register Caller %ecx Count register Caller %ebx Global Offset Table Base Register / Local register variable Callee %ebp Stack frame pointer (optional) Callee %esi Local register variable Callee %edi Local register variable Callee %esp Stack pointer Callee %st(0) Floating point stack - top %st(7) Floating point stack - bottom 4/2/2012 Juergen Ributzka 19
18 All arguments are passed on the stack The stack is always aligned to 4 bytes Arguments are promoted to 4 bytes Arguments are passed from right to left on the stack void foo( char c, short s, int i, long l, float f, double d); foo(1,2,3,4,5.0,6.0); Offset Stack (higher 4 byte) (lower 4 byte) /2/2012 Juergen Ributzka 20
19 Base Offset Content %ebp 4n+8 argument word n High Address 8 argument word 0 4 urn address %ebp 0 caller s %ebp %ebp %ebp -4-4x x words local space local variables, etc %esp 8 caller s %edi %esp 4 caller s %esi %esp 0 caller s %ebx Low Address 4/2/2012 Juergen Ributzka 21
20 IP... subl $4, %esp movl $5, (%esp) call foo movl 8(%ebp), %eax addl $1, %eax popl %ebp leave BP Stack Return Address SP 4/2/2012 Juergen Ributzka 22
21 IP... subl $4, %esp movl $5, (%esp) call foo movl 8(%ebp), %eax addl $1, %eax popl %ebp leave BP Stack Return Address (%ebp) SP 4/2/2012 Juergen Ributzka 23
22 IP... subl $4, %esp movl $5, (%esp) call foo movl 8(%ebp), %eax addl $1, %eax popl %ebp leave BP Stack Return Address (%ebp) SP 4/2/2012 Juergen Ributzka 24
23 IP... subl $4, %esp movl $5, (%esp) call foo movl 8(%ebp), %eax addl $1, %eax popl %ebp leave BP Stack Return Address (%ebp) SP 4/2/2012 Juergen Ributzka 25
24 IP... subl $4, %esp movl $5, (%esp) call foo movl 8(%ebp), %eax addl $1, %eax popl %ebp leave BP Stack Return Address (%ebp) 5 SP 4/2/2012 Juergen Ributzka 26
25 IP... subl $4, %esp movl $5, (%esp) call foo movl 8(%ebp), %eax addl $1, %eax popl %ebp leave BP Stack Return Address (%ebp) 5 Return Address SP 4/2/2012 Juergen Ributzka 27
26 IP... subl $4, %esp movl $5, (%esp) call foo movl 8(%ebp), %eax addl $1, %eax popl %ebp leave BP Stack Return Address (%ebp) 5 Return Address (%ebp) SP 4/2/2012 Juergen Ributzka 28
27 IP... subl $4, %esp movl $5, (%esp) call foo movl 8(%ebp), %eax addl $1, %eax popl %ebp leave BP Stack Return Address (%ebp) 5 Return Address (%ebp) SP 4/2/2012 Juergen Ributzka 29
28 IP... subl $4, %esp movl $5, (%esp) call foo movl 8(%ebp), %eax addl $1, %eax popl %ebp leave +8 BP Stack Return Address (%ebp) 5 Return Address (%ebp) SP 4/2/2012 Juergen Ributzka 30
29 IP... subl $4, %esp movl $5, (%esp) call foo movl 8(%ebp), %eax addl $1, %eax popl %ebp leave BP Stack Return Address (%ebp) 5 Return Address (%ebp) SP 4/2/2012 Juergen Ributzka 31
30 IP... subl $4, %esp movl $5, (%esp) call foo movl 8(%ebp), %eax addl $1, %eax popl %ebp leave BP Stack Return Address (%ebp) 5 Return Address SP 4/2/2012 Juergen Ributzka 32
31 IP... subl $4, %esp movl $5, (%esp) call foo movl 8(%ebp), %eax addl $1, %eax popl %ebp leave BP Stack Return Address (%ebp) 5 SP 4/2/2012 Juergen Ributzka 33
32 IP... subl $4, %esp movl $5, (%esp) call foo movl 8(%ebp), %eax addl $1, %eax popl %ebp leave BP Stack Return Address SP 4/2/2012 Juergen Ributzka 34
33 IP... subl $4, %esp movl $5, (%esp) call foo movl 8(%ebp), %eax addl $1, %eax popl %ebp leave BP Stack SP 4/2/2012 Juergen Ributzka 35
34 Caller needs to allocate memory for urn value Passes address as hidden first argument to the function Callee needs to remove hidden argument from the stack upon completion Also urns address in %eax After call 4n+4(%esp) argument word n 8(%esp) argument word 1 4(%esp) value address 0(%esp) urn address After urn argument word n argument word 1 undefined 4n-4(%esp) 0(%esp) 4/2/2012 Juergen Ributzka 36
35 0(%ebp) 12(%esp) 0(%esp) Original Intermediate Final arguments and automatic variables save area 3 words arguments and automatic variables save area 3 words arguments and automatic variables old save area 3 words 0(%ebp) undefined new space undefined new space 12(%esp) new save area 3 words 0(%esp) 4/2/2012 Juergen Ributzka 37
36 Object Code Models: Absolute Code Instructions hold absolute virtual addresses. The code has to be loaded at a specific address Position-independent Code All addresses are relative. Code can be loaded at any address. 4/2/2012 Juergen Ributzka 38
37 printf foo printf main printf bar 4/2/2012 Juergen Ributzka 39
38 printf foo static linked programs have a copy of the library functions they use included in the binary printf main printf bar 4/2/2012 Juergen Ributzka 40
39 foo main printf bar 4/2/2012 Juergen Ributzka 41
40 dynamic linked programs point to the same code of the library function foo main printf bar 4/2/2012 Juergen Ributzka 42
41 C CODE extern int src; extern int dst; extern int *ptr; ptr = &dst; *ptr = src; ABSOLUTE CODE.globl src, dst, ptr movl $dst, ptr movl ptr, %eax movl src, %edx movl %edx, (%eax 4/2/2012 Juergen Ributzka 43
42 C CODE extern int src; extern int dst; extern int *ptr; ptr = &dst; *ptr = src; POSITION-INDEPENDENT CODE.globl src, dst, ptr movl ptr@got(%ebx), %eax movl dst@got(%ebx), %edx movl %edx, (%eax) movl ptr@got(%ebx), %eax movl (%eax), %eax movl src@got(%ebx), %edx movl (%edx), %edx movl %edx, (%eax) 4/2/2012 Juergen Ributzka 44
43 shared library printf: &pushl $offset_printf scanf: &pushl $offset_scanf GOT PLT program main dynamic linker.plt0: pushl got_plus_4 jmp *got_plus_8 nop; nop nop; nop.plt1: jmp *printf pushl $offset_printf jmp *scanf pushl $offset_scanf 4/2/2012 Juergen Ributzka 45
44 shared library printf: &printf scanf: &pushl $offset_scanf GOT PLT program main dynamic linker.plt0: pushl got_plus_4 jmp *got_plus_8 nop; nop nop; nop.plt1: jmp *printf pushl $offset_printf jmp *scanf pushl $offset_scanf 4/2/2012 Juergen Ributzka 46
45 File Offset File Virtual Address 0 ELF Header Table 0x100 0x2bf00 0x30d00 Pogramm Header Table Text Segment 0x2be00 bytes Data Segment 0x4e00 bytes Section Header Table 0x x8073eff 0x8074f00 0x8079cff 4/2/2012 Juergen Ributzka 47
46 Text Data Type Load Load Offset 0x100 0x2bf00 Virtual Address 0x x8074f00 File Size 0x2be00 0x4e00 Memory Size 0x2be00 0x5e24 Alignment 0x1000 0x1000 4/2/2012 Juergen Ributzka 48
47 0x x x8073f00 0x8073fff ELF Header (padding) Text Data padding 0x100 bytes Text padding 0xf00 bytes Data Uninitialized Data Page padding 0x x8074f00 0x8079d00 0x807ad24 0x807b000 4/2/2012 Juergen Ributzka 49
48 0xffffffff 0x x7fffffff Dynamic Segment Data Segment 0x x8047fff 0x Text Segment Stack Segment 4/2/2012 Juergen Ributzka 50
49 Linkers & Loaders free draft at SYSTEM V APPLICATION BINARY INTERFACE Intel386 Architecture Processor Supplement, Fourth Edition System V Application Binary Interface AMD64 Architecture Processor Supplement, Draft Version /2/2012 Juergen Ributzka 51
Assembly 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
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. 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 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 informationCS 31: Intro to Systems Functions and the Stack. Martin Gagne Swarthmore College February 23, 2016
CS 31: Intro to Systems Functions and the Stack Martin Gagne Swarthmore College February 23, 2016 Reminders Late policy: you do not have to send me an email to inform me of a late submission before the
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 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 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 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 informationX86 Stack Calling Function POV
X86 Stack Calling Function POV Computer Systems Section 3.7 Stack Frame Reg Value ebp xffff FFF0 esp xffff FFE0 eax x0000 000E Memory Address Value xffff FFF8 xffff FFF4 x0000 0004 xffff FFF4 x0000 0003
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 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 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 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 informationX86 Review Process Layout, ISA, etc. CS642: Computer Security. Drew Davidson
X86 Review Process Layout, ISA, etc. CS642: Computer Security Drew Davidson davidson@cs.wisc.edu From Last Time ACL-based permissions (UNIX style) Read, Write, execute can be restricted on users and groups
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 informationMachine Programming 3: Procedures
Machine Programming 3: Procedures CS61, Lecture 5 Prof. Stephen Chong September 15, 2011 Announcements Assignment 2 (Binary bomb) due next week If you haven t yet please create a VM to make sure the infrastructure
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 informationCSE 351: Week 4. Tom Bergan, TA
CSE 35 Week 4 Tom Bergan, TA Does this code look okay? int binarysearch(int a[], int length, int key) { int low = 0; int high = length - ; while (low
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 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 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 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 informationTurning C into Object Code Code in files p1.c p2.c Compile with command: gcc -O p1.c p2.c -o p Use optimizations (-O) Put resulting binary in file p
Turning C into Object Code Code in files p1.c p2.c Compile with command: gcc -O p1.c p2.c -o p Use optimizations (-O) Put resulting binary in file p text C program (p1.c p2.c) Compiler (gcc -S) text Asm
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 informationAssembly I: Basic Operations. Jo, Heeseung
Assembly I: Basic Operations Jo, Heeseung Moving Data (1) Moving data: movl source, dest Move 4-byte ("long") word Lots of these in typical code Operand types Immediate: constant integer data - Like C
More informationCS642: Computer Security
X86 Review Process Layout, ISA, etc. CS642: Computer Security Drew Davidson davidson@cs.wisc.edu From Last Week ACL- based permissions (UNIX style) Read, Write, execute can be restricted on users and groups
More informationASSEMBLY I: BASIC OPERATIONS. Jo, Heeseung
ASSEMBLY I: BASIC OPERATIONS Jo, Heeseung MOVING DATA (1) Moving data: movl source, dest Move 4-byte ("long") word Lots of these in typical code Operand types Immediate: constant integer data - Like C
More informationadministrivia 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 informationAssembly Programmer s View Lecture 4A Machine-Level Programming I: Introduction
Assembly Programmer s View Lecture 4A Machine-Level Programming I: Introduction E I P CPU isters Condition Codes Addresses Data Instructions Memory Object Code Program Data OS Data Topics Assembly Programmer
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 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 informationW4118: PC Hardware and x86. Junfeng Yang
W4118: PC Hardware and x86 Junfeng Yang A PC How to make it do something useful? 2 Outline PC organization x86 instruction set gcc calling conventions PC emulation 3 PC board 4 PC organization One or more
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 informationx86 assembly CS449 Spring 2016
x86 assembly CS449 Spring 2016 CISC vs. RISC CISC [Complex instruction set Computing] - larger, more feature-rich instruction set (more operations, addressing modes, etc.). slower clock speeds. fewer general
More informationAssembly I: Basic Operations. Computer Systems Laboratory Sungkyunkwan University
Assembly I: Basic Operations Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Moving Data (1) Moving data: movl source, dest Move 4-byte ( long )
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 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 informationAccess. Young W. Lim Sat. Young W. Lim Access Sat 1 / 19
Access Young W. Lim 2017-06-10 Sat Young W. Lim Access 2017-06-10 Sat 1 / 19 Outline 1 Introduction References IA32 Operand Forms Data Movement Instructions Data Movement Examples Young W. Lim Access 2017-06-10
More informationSystems I. Machine-Level Programming V: Procedures
Systems I Machine-Level Programming V: Procedures Topics abstraction and implementation IA32 stack discipline Procedural Memory Usage void swap(int *xp, int *yp) int t0 = *xp; int t1 = *yp; *xp = t1; *yp
More informationHomework. In-line Assembly Code Machine Language Program Efficiency Tricks Reading PAL, pp 3-6, Practice Exam 1
Homework In-line Assembly Code Machine Language Program Efficiency Tricks Reading PAL, pp 3-6, 361-367 Practice Exam 1 1 In-line Assembly Code The gcc compiler allows you to put assembly instructions in-line
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 informationAccess. Young W. Lim Fri. Young W. Lim Access Fri 1 / 18
Access Young W. Lim 2017-01-27 Fri Young W. Lim Access 2017-01-27 Fri 1 / 18 Outline 1 Introduction References IA32 Operand Forms Data Movement Instructions Young W. Lim Access 2017-01-27 Fri 2 / 18 Based
More informationCAS CS Computer Systems Spring 2015 Solutions to Problem Set #2 (Intel Instructions) Due: Friday, March 20, 1:00 pm
CAS CS 210 - Computer Systems Spring 2015 Solutions to Problem Set #2 (Intel Instructions) Due: Friday, March 20, 1:00 pm This problem set is to be completed individually. Explain how you got to your answers
More informationCS61, Fall 2012 Midterm Review Section
CS61, Fall 2012 Midterm Review Section (10/16/2012) Q1: Hexadecimal and Binary Notation - Solve the following equations and put your answers in hex, decimal and binary. Hexadecimal Decimal Binary 15 +
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 informationCredits and Disclaimers
Credits and Disclaimers 1 The examples and discussion in the following slides have been adapted from a variety of sources, including: Chapter 3 of Computer Systems 2 nd Edition by Bryant and O'Hallaron
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 the
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 informationANITA S SUPER AWESOME RECITATION SLIDES
ANITA S SUPER AWESOME RECITATION SLIDES 15/18-213: Introduction to Computer Systems Stacks and Buflab, 11 Jun 2013 Anita Zhang, Section M WHAT S NEW (OR NOT) Bomblab is due tonight, 11:59 PM EDT Your late
More informationx86 architecture et similia
x86 architecture et similia 1 FREELY INSPIRED FROM CLASS 6.828, MIT A full PC has: PC architecture 2 an x86 CPU with registers, execution unit, and memory management CPU chip pins include address and data
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 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 informationLab 10: Introduction to x86 Assembly
CS342 Computer Security Handout # 8 Prof. Lyn Turbak Wednesday, Nov. 07, 2012 Wellesley College Revised Nov. 09, 2012 Lab 10: Introduction to x86 Assembly Revisions: Nov. 9 The sos O3.s file on p. 10 was
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 informationInstruction Set Architectures
Instruction Set Architectures! ISAs! Brief history of processors and architectures! C, assembly, machine code! Assembly basics: registers, operands, move instructions 1 What should the HW/SW interface
More informationFunction Calls and Stack
Function Calls and Stack Philipp Koehn 16 April 2018 1 functions Another Example 2 C code with an undefined function int main(void) { int a = 2; int b = do_something(a); urn b; } This can be successfully
More informationCMSC 313 Fall2009 Midterm Exam 2 Section 01 Nov 11, 2009
CMSC 313 Fall2009 Midterm Exam 2 Section 01 Nov 11, 2009 Name Score out of 70 UMBC Username Notes: a. Please write clearly. Unreadable answers receive no credit. b. For TRUE/FALSE questions, write the
More informationLecture 4 CIS 341: COMPILERS
Lecture 4 CIS 341: COMPILERS CIS 341 Announcements HW2: X86lite Available on the course web pages. Due: Weds. Feb. 7 th at midnight Pair-programming project Zdancewic CIS 341: Compilers 2 X86 Schematic
More informationUniversity of Washington
Roadmap C: car *c = malloc(sizeof(car)); c->miles = 100; c->gals = 17; float mpg = get_mpg(c); free(c); Assembly language: Machine code: Computer system: get_mpg: pushq %rbp movq %rsp, %rbp... popq %rbp
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 informationReverse Engineering II: Basics. Gergely Erdélyi Senior Antivirus Researcher
Reverse Engineering II: Basics Gergely Erdélyi Senior Antivirus Researcher Agenda Very basics Intel x86 crash course Basics of C Binary Numbers Binary Numbers 1 Binary Numbers 1 0 1 1 Binary Numbers 1
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 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 informationAssembly level Programming. 198:211 Computer Architecture. (recall) Von Neumann Architecture. Simplified hardware view. Lecture 10 Fall 2012
19:211 Computer Architecture Lecture 10 Fall 20 Topics:Chapter 3 Assembly Language 3.2 Register Transfer 3. ALU 3.5 Assembly level Programming We are now familiar with high level programming languages
More informationCS , Fall 2002 Exam 1
Andrew login ID: Full Name: CS 15-213, Fall 2002 Exam 1 October 8, 2002 Instructions: Make sure that your exam is not missing any sheets, then write your full name and Andrew login ID on the front. Write
More informationCS429: Computer Organization and Architecture
CS429: Computer Organization and Architecture Warren Hunt, Jr. and Bill Young Department of Computer Sciences University of Texas at Austin Last updated: October 1, 2014 at 12:03 CS429 Slideset 6: 1 Topics
More informationReverse Engineering II: The Basics
Reverse Engineering II: The Basics Gergely Erdélyi Senior Manager, Anti-malware Research Protecting the irreplaceable f-secure.com Binary Numbers 1 0 1 1 - Nibble B 1 0 1 1 1 1 0 1 - Byte B D 1 0 1 1 1
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 informationSystems I. Machine-Level Programming I: Introduction
Systems I Machine-Level Programming I: Introduction Topics Assembly Programmerʼs Execution Model Accessing Information Registers IA32 Processors Totally Dominate General Purpose CPU Market Evolutionary
More informationSungkyunkwan University
Switch statements IA 32 Procedures Stack Structure Calling Conventions Illustrations of Recursion & Pointers long switch_eg (long x, long y, long z) { long w = 1; switch(x) { case 1: w = y*z; break; case
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 informationMACHINE-LEVEL PROGRAMMING I: BASICS COMPUTER ARCHITECTURE AND ORGANIZATION
MACHINE-LEVEL PROGRAMMING I: BASICS COMPUTER ARCHITECTURE AND ORGANIZATION Today: Machine Programming I: Basics History of Intel processors and architectures C, assembly, machine code Assembly Basics:
More informationCS 3843 Final Exam Fall 2012
CS 3843 Final Exam Fall 2012 Name (Last), (First) ID Please indicate your session: Morning Afternoon You may use a calculator and two sheets of notes on this exam, but no other materials and no computer.
More informationCISC 360. Machine-Level Programming I: Introduction Sept. 18, 2008
CISC 360 Machine-Level Programming I: Introduction Sept. 18, 2008 Topics Assembly Programmerʼs Execution Model Accessing Information Registers Memory Arithmetic operations IA32 Processors Totally Dominate
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 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 informationUW CSE 351, Winter 2013 Midterm Exam
Full Name: Student ID: UW CSE 351, Winter 2013 Midterm Exam February 15, 2013 Instructions: Make sure that your exam is not missing any of the 9 pages, then write your full name and UW student ID on the
More informationCMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING
CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 16, SPRING 2013 TOPICS TODAY Project 6 Perils & Pitfalls of Memory Allocation C Function Call Conventions in Assembly Language PERILS
More informationProgram Exploitation Intro
Program Exploitation Intro x86 Assembly 04//2018 Security 1 Univeristà Ca Foscari, Venezia What is Program Exploitation "Making a program do something unexpected and not planned" The right bugs can be
More informationMachine-level Representation of Programs. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University
Machine-level Representation of Programs Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Program? 짬뽕라면 준비시간 :10 분, 조리시간 :10 분 재료라면 1개, 스프 1봉지, 오징어
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 informationData Representa/ons: IA32 + x86-64
X86-64 Instruc/on Set Architecture Instructor: Sanjeev Se(a 1 Data Representa/ons: IA32 + x86-64 Sizes of C Objects (in Bytes) C Data Type Typical 32- bit Intel IA32 x86-64 unsigned 4 4 4 int 4 4 4 long
More informationCSE2421 FINAL EXAM SPRING Name KEY. Instructions: Signature
CSE2421 FINAL EXAM SPRING 2013 Name KEY Instructions: This is a closed-book, closed-notes, closed-neighbor exam. Only a writing utensil is needed for this exam. No calculators allowed. If you need to go
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 informationMeet & Greet! Come hang out with your TAs and Fellow Students (& eat free insomnia cookies) When : TODAY!! 5-6 pm Where : 3rd Floor Atrium, CIT
Meet & Greet! Come hang out with your TAs and Fellow Students (& eat free insomnia cookies) When : TODAY!! 5-6 pm Where : 3rd Floor Atrium, CIT CS33 Intro to Computer Systems XI 1 Copyright 2017 Thomas
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 informationHow Software Executes
How Software Executes CS-576 Systems Security Instructor: Georgios Portokalidis Overview Introduction Anatomy of a program Basic assembly Anatomy of function calls (and returns) Memory Safety Intel x86
More informationBuffer Overflow Attack
Buffer Overflow Attack What every applicant for the hacker should know about the foundation of buffer overflow attacks By (Dalgona@wowhacker.org) Email: zinwon@gmail.com 2005 9 5 Abstract Buffer overflow.
More informationMachine-Level Programming I: Introduction Jan. 30, 2001
15-213 Machine-Level Programming I: Introduction Jan. 30, 2001 Topics Assembly Programmer s Execution Model Accessing Information Registers Memory Arithmetic operations IA32 Processors Totally Dominate
More informationICS143A: Principles of Operating Systems. Midterm recap, sample questions. Anton Burtsev February, 2017
ICS143A: Principles of Operating Systems Midterm recap, sample questions Anton Burtsev February, 2017 Describe the x86 address translation pipeline (draw figure), explain stages. Address translation What
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 informationAssignment 11: functions, calling conventions, and the stack
Assignment 11: functions, calling conventions, and the stack ECEN 4553 & 5013, CSCI 4555 & 5525 Prof. Jeremy G. Siek December 5, 2008 The goal of this week s assignment is to remove function definitions
More informationGiving credit where credit is due
CSCE 230J Computer Organization Machine-Level Programming I: Introduction Dr. Steve Goddard goddard@cse.unl.edu Giving credit where credit is due Most of slides for this lecture are based on slides created
More informationInstruction Set Architectures
Instruction Set Architectures ISAs Brief history of processors and architectures C, assembly, machine code Assembly basics: registers, operands, move instructions 1 What should the HW/SW interface contain?
More informationComputer Labs: Profiling and Optimization
Computer Labs: Profiling and Optimization 2 o MIEIC Pedro F. Souto (pfs@fe.up.pt) December 15, 2010 Optimization Speed matters, and it depends mostly on the right choice of Data structures Algorithms If
More informationCS165 Computer Security. Understanding low-level program execution Oct 1 st, 2015
CS165 Computer Security Understanding low-level program execution Oct 1 st, 2015 A computer lets you make more mistakes faster than any invention in human history - with the possible exceptions of handguns
More informationProcesses (Intro) Yannis Smaragdakis, U. Athens
Processes (Intro) Yannis Smaragdakis, U. Athens Process: CPU Virtualization Process = Program, instantiated has memory, code, current state What kind of memory do we have? registers + address space Let's
More information