Download presentation
Presentation is loading. Please wait.
Published byRobyn Norman Modified over 8 years ago
1
The Runtime Environment CSE 340 – Principles of Programming Languages Fall 2015 Adam Doupé Arizona State University http://adamdoupe.com
2
Adam Doupé, Principles of Programming Languages Locations and Names What is the semantic distinction between locations and names? How does the compiler actually implement locations and names? –How does the compiler map names to memory locations? We are going to look into this process –Assuming static scoping 2
3
Adam Doupé, Principles of Programming Languages Global Variables Where can the compiler put variables? –Memory –Registers –Disk –"Cloud" What are the constraints on those variables? –Who can access them? –Who can't? 3
4
Adam Doupé, Principles of Programming Languages int a; int b; float c; int main() { a = 10; b = 100; c = 10.45; a = a + b; return 0; } 4 a @ 0x8049634 b @ 0x8049638 c @ 0x804963c movl $0xa,0x8049634 movl $0x64,0x8049638 mov $0x41273333,%eax mov %eax,0x804963c mov 0x8049634,%edx mov 0x8049638,%eax lea (%edx,%eax,1),%eax mov %eax,0x8049634 a @ A b @ B c @ C mem[A] = 10 mem[B] = 100 mem[C] = 10.45 mem[A] = mem[A] + mem[B]
5
Adam Doupé, Principles of Programming Languages Local Variables What are the constraints on local variables? Where can the compiler place local variables? –Global Memory (one for each function) 5
6
Adam Doupé, Principles of Programming Languages int fact(int n) { if (n == 0) { return 1; } else { return fact(n-1) * n; } } 6
7
Adam Doupé, Principles of Programming Languages Local Variables What are the constraints on local variables? Where can the compiler place local variables? –Global Memory (one for each function) –"Scratch memory" for each function 7
8
Adam Doupé, Principles of Programming Languages The Stack Stack is essentially scratch memory for functions –Used in MIPS, ARM, x86, and x86-64 processors Starts at high memory addresses, and grows down Functions are free to push registers or values onto the stack, or pop values from the stack into registers The assembly language supports this on x86 – %esp holds the address of the top of the stack – push %eax decrements the stack pointer ( %esp ) then stores the value in %eax to the location pointed to by the stack pointer – pop %eax stores the value at the location pointed to by the stack pointer into %eax, then increments the stack pointer ( %esp ) 8
9
Adam Doupé, Principles of Programming Languages Stack Example … … Garbage 9 0xFFFFFFFF 0x00000000 0x10000 %eax0xa %ebx0x0 %esp0x10000 push %eax pop %ebx
10
Adam Doupé, Principles of Programming Languages Stack Example … … Garbage 10 0xFFFFFFFF 0x00000000 0x10000 %eax0xa %ebx0x0 %esp0x10000 push %eax pop %ebx
11
Adam Doupé, Principles of Programming Languages Stack Example … … Garbage 11 0xFFFFFFFF 0x00000000 0x10000 %eax0xa %ebx0x0 %esp0x10000 push %eax pop %ebx
12
Adam Doupé, Principles of Programming Languages Stack Example … 0xa … Garbage 12 0xFFFFFFFF 0x00000000 0x10000 %eax0xa %ebx0x0 %esp0xFFFC push %eax pop %ebx
13
Adam Doupé, Principles of Programming Languages Stack Example … 0xa … Garbage 13 0xFFFFFFFF 0x00000000 0x10000 %eax0xa %ebx0x0 %esp0xFFFC push %eax pop %ebx
14
Adam Doupé, Principles of Programming Languages Stack Example … 0xa … Garbage 14 0xFFFFFFFF 0x00000000 0x10000 %eax0xa %ebx0xa %esp0xFFFC push %eax pop %ebx
15
Adam Doupé, Principles of Programming Languages Stack Example … 0xa … Garbage 15 0xFFFFFFFF 0x00000000 0x10000 %eax0xa %ebx0xa %esp0x10000 push %eax pop %ebx
16
Adam Doupé, Principles of Programming Languages Function Frame Functions would like to use the stack to allocate space for their local variables Can we use the stack pointer for this? –Yes, however stack pointer can change throughout program execution Frame pointer points to the start of the function's frame on the stack –Each local variable will be (different) offsets of the frame pointer –In x86, frame pointer is called the base pointer, and is stored in %ebp 16
17
Adam Doupé, Principles of Programming Languages int main() { int a; int b; float c; a = 10; b = 100; c = 10.45; a = a + b; return 0; } 17 a @ %ebp – 0xc b @ %ebp – 0x8 c @ %ebp – 0x4 mov %esp,%ebp sub $0x10,%esp movl $0xa,-0xc(%ebp) movl $0x64,-0x8(%ebp) mov $0x41273333,%eax mov %eax,-0x4(%ebp) mov -0x8(%ebp),%eax add %eax,-0xc(%ebp) a @ %ebp + A b @ %ebp + B c @ %ebp + C mem[%ebp+A] = 10 mem[%ebp+B] = 100 mem[%ebp+C] = 10.45 mem[%ebp+A] = mem[%ebp+A] + mem[%ebp+B]
18
Adam Doupé, Principles of Programming Languages Function Frame … 18 0xFFFFFFFF 0x00000000 0x10000 %eax %esp0x10000 %ebp0x10000 mov %esp,%ebp sub $0x10,%esp movl $0xa,-0xc(%ebp) movl $0x64,-0x8(%ebp) mov $0x41273333,%eax mov %eax,-0x4(%ebp) mov -0x8(%ebp),%eax add %eax,-0xc(%ebp)
19
Adam Doupé, Principles of Programming Languages Function Frame … 19 0xFFFFFFFF 0x00000000 0x10000 %eax %esp0x10000 %ebp0x10000 mov %esp,%ebp sub $0x10,%esp movl $0xa,-0xc(%ebp) movl $0x64,-0x8(%ebp) mov $0x41273333,%eax mov %eax,-0x4(%ebp) mov -0x8(%ebp),%eax add %eax,-0xc(%ebp)
20
Adam Doupé, Principles of Programming Languages Function Frame … 20 0xFFFFFFFF 0x00000000 0x10000 %eax %esp0xFFF0 %ebp0x10000 mov %esp,%ebp sub $0x10,%esp movl $0xa,-0xc(%ebp) movl $0x64,-0x8(%ebp) mov $0x41273333,%eax mov %eax,-0x4(%ebp) mov -0x8(%ebp),%eax add %eax,-0xc(%ebp)
21
Adam Doupé, Principles of Programming Languages Function Frame … 21 0xFFFFFFFF 0x00000000 0x10000 %eax %esp0xFFF0 %ebp0x10000 mov %esp,%ebp sub $0x10,%esp movl $0xa,-0xc(%ebp) movl $0x64,-0x8(%ebp) mov $0x41273333,%eax mov %eax,-0x4(%ebp) mov -0x8(%ebp),%eax add %eax,-0xc(%ebp) 0xFFFC 0xFFF8 0xFFF4 0xFFF0
22
Adam Doupé, Principles of Programming Languages Function Frame … 0xa 22 0xFFFFFFFF 0x00000000 0x10000 %eax %esp0xFFF0 %ebp0x10000 mov %esp,%ebp sub $0x10,%esp movl $0xa,-0xc(%ebp) movl $0x64,-0x8(%ebp) mov $0x41273333,%eax mov %eax,-0x4(%ebp) mov -0x8(%ebp),%eax add %eax,-0xc(%ebp) 0xFFFC 0xFFF8 0xFFF4 0xFFF0
23
Adam Doupé, Principles of Programming Languages Function Frame … 0xa 23 0xFFFFFFFF 0x00000000 0x10000 %eax %esp0xFFF0 %ebp0x10000 mov %esp,%ebp sub $0x10,%esp movl $0xa,-0xc(%ebp) movl $0x64,-0x8(%ebp) mov $0x41273333,%eax mov %eax,-0x4(%ebp) mov -0x8(%ebp),%eax add %eax,-0xc(%ebp) 0xFFFC 0xFFF8 0xFFF4 0xFFF0
24
Adam Doupé, Principles of Programming Languages Function Frame … 0x64 0xa 24 0xFFFFFFFF 0x00000000 0x10000 %eax %esp0xFFF0 %ebp0x10000 mov %esp,%ebp sub $0x10,%esp movl $0xa,-0xc(%ebp) movl $0x64,-0x8(%ebp) mov $0x41273333,%eax mov %eax,-0x4(%ebp) mov -0x8(%ebp),%eax add %eax,-0xc(%ebp) 0xFFFC 0xFFF8 0xFFF4 0xFFF0
25
Adam Doupé, Principles of Programming Languages Function Frame … 0x64 0xa 25 0xFFFFFFFF 0x00000000 0x10000 %eax %esp0xFFF0 %ebp0x10000 mov %esp,%ebp sub $0x10,%esp movl $0xa,-0xc(%ebp) movl $0x64,-0x8(%ebp) mov $0x41273333,%eax mov %eax,-0x4(%ebp) mov -0x8(%ebp),%eax add %eax,-0xc(%ebp) 0xFFFC 0xFFF8 0xFFF4 0xFFF0
26
Adam Doupé, Principles of Programming Languages Function Frame … 0x64 0xa 26 0xFFFFFFFF 0x00000000 0x10000 %eax0x41273333 %esp0xFFF0 %ebp0x10000 mov %esp,%ebp sub $0x10,%esp movl $0xa,-0xc(%ebp) movl $0x64,-0x8(%ebp) mov $0x41273333,%eax mov %eax,-0x4(%ebp) mov -0x8(%ebp),%eax add %eax,-0xc(%ebp) 0xFFFC 0xFFF8 0xFFF4 0xFFF0
27
Adam Doupé, Principles of Programming Languages Function Frame … 0x64 0xa 27 0xFFFFFFFF 0x00000000 0x10000 %eax0x41273333 %esp0xFFF0 %ebp0x10000 mov %esp,%ebp sub $0x10,%esp movl $0xa,-0xc(%ebp) movl $0x64,-0x8(%ebp) mov $0x41273333,%eax mov %eax,-0x4(%ebp) mov -0x8(%ebp),%eax add %eax,-0xc(%ebp) 0xFFFC 0xFFF8 0xFFF4 0xFFF0
28
Adam Doupé, Principles of Programming Languages Function Frame … 0x41273333 0x64 0xa 28 0xFFFFFFFF 0x00000000 0x10000 %eax0x41273333 %esp0xFFF0 %ebp0x10000 mov %esp,%ebp sub $0x10,%esp movl $0xa,-0xc(%ebp) movl $0x64,-0x8(%ebp) mov $0x41273333,%eax mov %eax,-0x4(%ebp) mov -0x8(%ebp),%eax add %eax,-0xc(%ebp) 0xFFFC 0xFFF8 0xFFF4 0xFFF0
29
Adam Doupé, Principles of Programming Languages Function Frame … 0x41273333 0x64 0xa 29 0xFFFFFFFF 0x00000000 0x10000 %eax0x41273333 %esp0xFFF0 %ebp0x10000 mov %esp,%ebp sub $0x10,%esp movl $0xa,-0xc(%ebp) movl $0x64,-0x8(%ebp) mov $0x41273333,%eax mov %eax,-0x4(%ebp) mov -0x8(%ebp),%eax add %eax,-0xc(%ebp) 0xFFFC 0xFFF8 0xFFF4 0xFFF0 c b a
30
Adam Doupé, Principles of Programming Languages Function Frame … 0x41273333 0x64 0xa 30 0xFFFFFFFF 0x00000000 0x10000 %eax0x64 %esp0xFFF0 %ebp0x10000 mov %esp,%ebp sub $0x10,%esp movl $0xa,-0xc(%ebp) movl $0x64,-0x8(%ebp) mov $0x41273333,%eax mov %eax,-0x4(%ebp) mov -0x8(%ebp),%eax add %eax,-0xc(%ebp) 0xFFFC 0xFFF8 0xFFF4 0xFFF0 c b a
31
Adam Doupé, Principles of Programming Languages Function Frame … 0x41273333 0x64 0xa 31 0xFFFFFFFF 0x00000000 0x10000 %eax0x64 %esp0xFFF0 %ebp0x10000 mov %esp,%ebp sub $0x10,%esp movl $0xa,-0xc(%ebp) movl $0x64,-0x8(%ebp) mov $0x41273333,%eax mov %eax,-0x4(%ebp) mov -0x8(%ebp),%eax add %eax,-0xc(%ebp) 0xFFFC 0xFFF8 0xFFF4 0xFFF0 c b a
32
Adam Doupé, Principles of Programming Languages Function Frame … 0x41273333 0x64 0x6E 32 0xFFFFFFFF 0x00000000 0x10000 %eax0x64 %esp0xFFF0 %ebp0x10000 mov %esp,%ebp sub $0x10,%esp movl $0xa,-0xc(%ebp) movl $0x64,-0x8(%ebp) mov $0x41273333,%eax mov %eax,-0x4(%ebp) mov -0x8(%ebp),%eax add %eax,-0xc(%ebp) 0xFFFC 0xFFF8 0xFFF4 0xFFF0 c b a
33
Adam Doupé, Principles of Programming Languages Function Frame … 0x41273333 0x64 0x6E 33 0xFFFFFFFF 0x00000000 0x10000 %eax0x64 %esp0xFFF0 %ebp0x10000 mov %esp,%ebp sub $0x10,%esp movl $0xa,-0xc(%ebp) movl $0x64,-0x8(%ebp) mov $0x41273333,%eax mov %eax,-0x4(%ebp) mov -0x8(%ebp),%eax add %eax,-0xc(%ebp) 0xFFFC 0xFFF8 0xFFF4 0xFFF0 c b a
34
Adam Doupé, Principles of Programming Languages Functions Declarations –Function name –Formal parameters (names and types) –Return type Invocation –f(x 1,x 2,…,x k ) –x 1,x 2,...,x k are expressions –x 1,x 2,...x k are called the actual parameters –Invoking function must create the frame on the stack with enough space to hold the actual parameters 34
35
Adam Doupé, Principles of Programming Languages Function Frames Allows us to allocate memory for the function's local variables However, when considering calling a function, what other information do we need? –Return value –Parameters –Our frame pointer –Return address (where to start program execution when function returns) –Local variables –Temporary variables 35
36
Adam Doupé, Principles of Programming Languages Calling Convention All of the previous information must be stored on the stack in order to call the function Who should store that information? –Caller? –Callee? Thus, we need to define a convention of who pushes/stores what values on the stack to call a function –Varies based on processor, operating system, compiler, or type of call 36
37
Adam Doupé, Principles of Programming Languages x86 Linux Calling Convention (cdecl) Caller (in this order) –Pushes arguments onto the stack (in right to left order) –Pushes address of instruction after call Callee –Pushes previous frame pointer onto stack –Creates space on stack for local variables –Ensures that stack is consistant on return –Return value in %eax register 37
38
Adam Doupé, Principles of Programming Languages int callee(int a, int b) { return a + b + 1; } int main() { int a; a = callee(10, 40); return a; } 38 callee: push %ebp mov %esp,%ebp mov 0xc(%ebp),%eax mov 0x8(%ebp),%edx lea (%edx,%eax,1),%eax add $0x1,%eax pop %ebp ret main: push %ebp mov %esp,%ebp sub $0x18,%esp movl $0x28,0x4(%esp) movl $0xa,(%esp) call callee mov %eax,-0x4(%ebp) mov -0x4(%ebp),%eax leave ret prologue epilogue prologue epilogue
39
Adam Doupé, Principles of Programming Languages 39 0xFFFFFFFF 0x00000000 0xfd2d4 %eax %edx %esp0xfd2d4 %ebp0xfd2c0 %eip0x80483a5 callee: push %ebp mov %esp,%ebp mov 0xc(%ebp),%eax mov 0x8(%ebp),%edx lea (%edx,%eax,1),%eax add $0x1,%eax pop %ebp ret main: push %ebp mov %esp,%ebp sub $0x18,%esp movl $0x28,0x4(%esp) movl $0xa,(%esp) call 0x8048394 mov %eax,-0x4(%ebp) mov -0x4(%ebp),%eax leave ret 0x8048394 0x8048395 0x8048397 0x804839a 0x804839d 0x80483a0 0x80483a3 0x80483a4 0x80483a5 0x80483a6 0x80483a8 0x80483ab 0x80483b3 0x80483ba 0x80483bf 0x80483c2 0x80483c5 0x80483c6
40
Adam Doupé, Principles of Programming Languages 40 0xFFFFFFFF 0x00000000 %eax %edx %esp0xfd2d0 %ebp0xfd2c0 %eip0x80483a5 callee: push %ebp mov %esp,%ebp mov 0xc(%ebp),%eax mov 0x8(%ebp),%edx lea (%edx,%eax,1),%eax add $0x1,%eax pop %ebp ret main: push %ebp mov %esp,%ebp sub $0x18,%esp movl $0x28,0x4(%esp) movl $0xa,(%esp) call 0x8048394 mov %eax,-0x4(%ebp) mov -0x4(%ebp),%eax leave ret 0x8048394 0x8048395 0x8048397 0x804839a 0x804839d 0x80483a0 0x80483a3 0x80483a4 0x80483a5 0x80483a6 0x80483a8 0x80483ab 0x80483b3 0x80483ba 0x80483bf 0x80483c2 0x80483c5 0x80483c6 0xfd2d4
41
Adam Doupé, Principles of Programming Languages 0xfd2c0 41 0xFFFFFFFF 0x00000000 %eax %edx %esp0xfd2d0 %ebp0xfd2c0 %eip0x80483a5 callee: push %ebp mov %esp,%ebp mov 0xc(%ebp),%eax mov 0x8(%ebp),%edx lea (%edx,%eax,1),%eax add $0x1,%eax pop %ebp ret main: push %ebp mov %esp,%ebp sub $0x18,%esp movl $0x28,0x4(%esp) movl $0xa,(%esp) call 0x8048394 mov %eax,-0x4(%ebp) mov -0x4(%ebp),%eax leave ret 0x8048394 0x8048395 0x8048397 0x804839a 0x804839d 0x80483a0 0x80483a3 0x80483a4 0x80483a5 0x80483a6 0x80483a8 0x80483ab 0x80483b3 0x80483ba 0x80483bf 0x80483c2 0x80483c5 0x80483c6 0xfd2d4
42
Adam Doupé, Principles of Programming Languages 0xfd2c0 42 0xFFFFFFFF 0x00000000 %eax %edx %esp0xfd2d0 %ebp0xfd2c0 %eip0x80483a5 callee: push %ebp mov %esp,%ebp mov 0xc(%ebp),%eax mov 0x8(%ebp),%edx lea (%edx,%eax,1),%eax add $0x1,%eax pop %ebp ret main: push %ebp mov %esp,%ebp sub $0x18,%esp movl $0x28,0x4(%esp) movl $0xa,(%esp) call 0x8048394 mov %eax,-0x4(%ebp) mov -0x4(%ebp),%eax leave ret 0x8048394 0x8048395 0x8048397 0x804839a 0x804839d 0x80483a0 0x80483a3 0x80483a4 0x80483a5 0x80483a6 0x80483a8 0x80483ab 0x80483b3 0x80483ba 0x80483bf 0x80483c2 0x80483c5 0x80483c6 0xfd2d4
43
Adam Doupé, Principles of Programming Languages 0xfd2c0 43 0xFFFFFFFF 0x00000000 %eax %edx %esp0xfd2d0 %ebp0xfd2c0 %eip0x80483a6 callee: push %ebp mov %esp,%ebp mov 0xc(%ebp),%eax mov 0x8(%ebp),%edx lea (%edx,%eax,1),%eax add $0x1,%eax pop %ebp ret main: push %ebp mov %esp,%ebp sub $0x18,%esp movl $0x28,0x4(%esp) movl $0xa,(%esp) call 0x8048394 mov %eax,-0x4(%ebp) mov -0x4(%ebp),%eax leave ret 0x8048394 0x8048395 0x8048397 0x804839a 0x804839d 0x80483a0 0x80483a3 0x80483a4 0x80483a5 0x80483a6 0x80483a8 0x80483ab 0x80483b3 0x80483ba 0x80483bf 0x80483c2 0x80483c5 0x80483c6 0xfd2d4
44
Adam Doupé, Principles of Programming Languages 0xfd2c0 44 0xFFFFFFFF 0x00000000 %eax %edx %esp0xfd2d0 %ebp0xfd2d0 %eip0x80483a6 callee: push %ebp mov %esp,%ebp mov 0xc(%ebp),%eax mov 0x8(%ebp),%edx lea (%edx,%eax,1),%eax add $0x1,%eax pop %ebp ret main: push %ebp mov %esp,%ebp sub $0x18,%esp movl $0x28,0x4(%esp) movl $0xa,(%esp) call 0x8048394 mov %eax,-0x4(%ebp) mov -0x4(%ebp),%eax leave ret 0x8048394 0x8048395 0x8048397 0x804839a 0x804839d 0x80483a0 0x80483a3 0x80483a4 0x80483a5 0x80483a6 0x80483a8 0x80483ab 0x80483b3 0x80483ba 0x80483bf 0x80483c2 0x80483c5 0x80483c6 0xfd2d4
45
Adam Doupé, Principles of Programming Languages 0xfd2c0 45 0xFFFFFFFF 0x00000000 %eax %edx %esp0xfd2d0 %ebp0xfd2d0 %eip0x80483a8 callee: push %ebp mov %esp,%ebp mov 0xc(%ebp),%eax mov 0x8(%ebp),%edx lea (%edx,%eax,1),%eax add $0x1,%eax pop %ebp ret main: push %ebp mov %esp,%ebp sub $0x18,%esp movl $0x28,0x4(%esp) movl $0xa,(%esp) call 0x8048394 mov %eax,-0x4(%ebp) mov -0x4(%ebp),%eax leave ret 0x8048394 0x8048395 0x8048397 0x804839a 0x804839d 0x80483a0 0x80483a3 0x80483a4 0x80483a5 0x80483a6 0x80483a8 0x80483ab 0x80483b3 0x80483ba 0x80483bf 0x80483c2 0x80483c5 0x80483c6 0xfd2d4
46
Adam Doupé, Principles of Programming Languages 0xfd2c0 46 0xFFFFFFFF 0x00000000 %eax %edx %esp0xfd2b8 %ebp0xfd2d0 %eip0x80483a8 callee: push %ebp mov %esp,%ebp mov 0xc(%ebp),%eax mov 0x8(%ebp),%edx lea (%edx,%eax,1),%eax add $0x1,%eax pop %ebp ret main: push %ebp mov %esp,%ebp sub $0x18,%esp movl $0x28,0x4(%esp) movl $0xa,(%esp) call 0x8048394 mov %eax,-0x4(%ebp) mov -0x4(%ebp),%eax leave ret 0x8048394 0x8048395 0x8048397 0x804839a 0x804839d 0x80483a0 0x80483a3 0x80483a4 0x80483a5 0x80483a6 0x80483a8 0x80483ab 0x80483b3 0x80483ba 0x80483bf 0x80483c2 0x80483c5 0x80483c6 0xfd2d4 0xfd2d0 0xfd2b8
47
Adam Doupé, Principles of Programming Languages 0xfd2c0 47 0xFFFFFFFF 0x00000000 %eax %edx %esp0xfd2b8 %ebp0xfd2d0 %eip0x80483ab callee: push %ebp mov %esp,%ebp mov 0xc(%ebp),%eax mov 0x8(%ebp),%edx lea (%edx,%eax,1),%eax add $0x1,%eax pop %ebp ret main: push %ebp mov %esp,%ebp sub $0x18,%esp movl $0x28,0x4(%esp) movl $0xa,(%esp) call 0x8048394 mov %eax,-0x4(%ebp) mov -0x4(%ebp),%eax leave ret 0x8048394 0x8048395 0x8048397 0x804839a 0x804839d 0x80483a0 0x80483a3 0x80483a4 0x80483a5 0x80483a6 0x80483a8 0x80483ab 0x80483b3 0x80483ba 0x80483bf 0x80483c2 0x80483c5 0x80483c6 0xfd2d4 0xfd2d0 0xfd2b8 0xfd2bc
48
Adam Doupé, Principles of Programming Languages 0xfd2c0 0x28 48 0xFFFFFFFF 0x00000000 %eax %edx %esp0xfd2b8 %ebp0xfd2d0 %eip0x80483ab callee: push %ebp mov %esp,%ebp mov 0xc(%ebp),%eax mov 0x8(%ebp),%edx lea (%edx,%eax,1),%eax add $0x1,%eax pop %ebp ret main: push %ebp mov %esp,%ebp sub $0x18,%esp movl $0x28,0x4(%esp) movl $0xa,(%esp) call 0x8048394 mov %eax,-0x4(%ebp) mov -0x4(%ebp),%eax leave ret 0x8048394 0x8048395 0x8048397 0x804839a 0x804839d 0x80483a0 0x80483a3 0x80483a4 0x80483a5 0x80483a6 0x80483a8 0x80483ab 0x80483b3 0x80483ba 0x80483bf 0x80483c2 0x80483c5 0x80483c6 0xfd2d4 0xfd2d0 0xfd2b8 0xfd2bc
49
Adam Doupé, Principles of Programming Languages 0xfd2c0 0x28 49 0xFFFFFFFF 0x00000000 %eax %edx %esp0xfd2b8 %ebp0xfd2d0 %eip0x80483b3 callee: push %ebp mov %esp,%ebp mov 0xc(%ebp),%eax mov 0x8(%ebp),%edx lea (%edx,%eax,1),%eax add $0x1,%eax pop %ebp ret main: push %ebp mov %esp,%ebp sub $0x18,%esp movl $0x28,0x4(%esp) movl $0xa,(%esp) call 0x8048394 mov %eax,-0x4(%ebp) mov -0x4(%ebp),%eax leave ret 0x8048394 0x8048395 0x8048397 0x804839a 0x804839d 0x80483a0 0x80483a3 0x80483a4 0x80483a5 0x80483a6 0x80483a8 0x80483ab 0x80483b3 0x80483ba 0x80483bf 0x80483c2 0x80483c5 0x80483c6 0xfd2d4 0xfd2d0 0xfd2b8 0xfd2bc
50
Adam Doupé, Principles of Programming Languages 0xfd2c0 0x28 0xa 50 0xFFFFFFFF 0x00000000 %eax %edx %esp0xfd2b8 %ebp0xfd2d0 %eip0x80483b3 callee: push %ebp mov %esp,%ebp mov 0xc(%ebp),%eax mov 0x8(%ebp),%edx lea (%edx,%eax,1),%eax add $0x1,%eax pop %ebp ret main: push %ebp mov %esp,%ebp sub $0x18,%esp movl $0x28,0x4(%esp) movl $0xa,(%esp) call 0x8048394 mov %eax,-0x4(%ebp) mov -0x4(%ebp),%eax leave ret 0x8048394 0x8048395 0x8048397 0x804839a 0x804839d 0x80483a0 0x80483a3 0x80483a4 0x80483a5 0x80483a6 0x80483a8 0x80483ab 0x80483b3 0x80483ba 0x80483bf 0x80483c2 0x80483c5 0x80483c6 0xfd2d4 0xfd2d0 0xfd2b8 0xfd2bc
51
Adam Doupé, Principles of Programming Languages 0xfd2c0 0x28 0xa 51 0xFFFFFFFF 0x00000000 %eax %edx %esp0xfd2b8 %ebp0xfd2d0 %eip0x80483ba callee: push %ebp mov %esp,%ebp mov 0xc(%ebp),%eax mov 0x8(%ebp),%edx lea (%edx,%eax,1),%eax add $0x1,%eax pop %ebp ret main: push %ebp mov %esp,%ebp sub $0x18,%esp movl $0x28,0x4(%esp) movl $0xa,(%esp) call 0x8048394 mov %eax,-0x4(%ebp) mov -0x4(%ebp),%eax leave ret 0x8048394 0x8048395 0x8048397 0x804839a 0x804839d 0x80483a0 0x80483a3 0x80483a4 0x80483a5 0x80483a6 0x80483a8 0x80483ab 0x80483b3 0x80483ba 0x80483bf 0x80483c2 0x80483c5 0x80483c6 0xfd2d4 0xfd2d0 0xfd2b8 0xfd2bc
52
Adam Doupé, Principles of Programming Languages 0xfd2c0 0x28 0xa 52 0xFFFFFFFF 0x00000000 %eax %edx %esp0xfd2b4 %ebp0xfd2d0 %eip0x80483ba callee: push %ebp mov %esp,%ebp mov 0xc(%ebp),%eax mov 0x8(%ebp),%edx lea (%edx,%eax,1),%eax add $0x1,%eax pop %ebp ret main: push %ebp mov %esp,%ebp sub $0x18,%esp movl $0x28,0x4(%esp) movl $0xa,(%esp) call 0x8048394 mov %eax,-0x4(%ebp) mov -0x4(%ebp),%eax leave ret 0x8048394 0x8048395 0x8048397 0x804839a 0x804839d 0x80483a0 0x80483a3 0x80483a4 0x80483a5 0x80483a6 0x80483a8 0x80483ab 0x80483b3 0x80483ba 0x80483bf 0x80483c2 0x80483c5 0x80483c6 0xfd2d4 0xfd2d0 0xfd2b8 0xfd2bc
53
Adam Doupé, Principles of Programming Languages 0xfd2c0 0x28 0xa 0x80483bf 53 0xFFFFFFFF 0x00000000 %eax %edx %esp0xfd2b4 %ebp0xfd2d0 %eip0x8048394 callee: push %ebp mov %esp,%ebp mov 0xc(%ebp),%eax mov 0x8(%ebp),%edx lea (%edx,%eax,1),%eax add $0x1,%eax pop %ebp ret main: push %ebp mov %esp,%ebp sub $0x18,%esp movl $0x28,0x4(%esp) movl $0xa,(%esp) call 0x8048394 mov %eax,-0x4(%ebp) mov -0x4(%ebp),%eax leave ret 0x8048394 0x8048395 0x8048397 0x804839a 0x804839d 0x80483a0 0x80483a3 0x80483a4 0x80483a5 0x80483a6 0x80483a8 0x80483ab 0x80483b3 0x80483ba 0x80483bf 0x80483c2 0x80483c5 0x80483c6 0xfd2d4 0xfd2d0 0xfd2b8 0xfd2bc 0xfd2b4
54
Adam Doupé, Principles of Programming Languages 0xfd2c0 0x28 0xa 0x80483bf 54 0xFFFFFFFF 0x00000000 %eax %edx %esp0xfd2b4 %ebp0xfd2d0 %eip0x8048394 callee: push %ebp mov %esp,%ebp mov 0xc(%ebp),%eax mov 0x8(%ebp),%edx lea (%edx,%eax,1),%eax add $0x1,%eax pop %ebp ret main: push %ebp mov %esp,%ebp sub $0x18,%esp movl $0x28,0x4(%esp) movl $0xa,(%esp) call 0x8048394 mov %eax,-0x4(%ebp) mov -0x4(%ebp),%eax leave ret 0x8048394 0x8048395 0x8048397 0x804839a 0x804839d 0x80483a0 0x80483a3 0x80483a4 0x80483a5 0x80483a6 0x80483a8 0x80483ab 0x80483b3 0x80483ba 0x80483bf 0x80483c2 0x80483c5 0x80483c6 0xfd2d4 0xfd2d0 0xfd2b8 0xfd2bc 0xfd2b4
55
Adam Doupé, Principles of Programming Languages 0xfd2c0 0x28 0xa 0x80483bf 55 0xFFFFFFFF 0x00000000 %eax %edx %esp0xfd2b0 %ebp0xfd2d0 %eip0x8048394 callee: push %ebp mov %esp,%ebp mov 0xc(%ebp),%eax mov 0x8(%ebp),%edx lea (%edx,%eax,1),%eax add $0x1,%eax pop %ebp ret main: push %ebp mov %esp,%ebp sub $0x18,%esp movl $0x28,0x4(%esp) movl $0xa,(%esp) call 0x8048394 mov %eax,-0x4(%ebp) mov -0x4(%ebp),%eax leave ret 0x8048394 0x8048395 0x8048397 0x804839a 0x804839d 0x80483a0 0x80483a3 0x80483a4 0x80483a5 0x80483a6 0x80483a8 0x80483ab 0x80483b3 0x80483ba 0x80483bf 0x80483c2 0x80483c5 0x80483c6 0xfd2d4 0xfd2d0 0xfd2b8 0xfd2bc 0xfd2b4 0xfd2b0
56
Adam Doupé, Principles of Programming Languages 0xfd2c0 0x28 0xa 0x80483bf 56 0xFFFFFFFF 0x00000000 %eax %edx %esp0xfd2b0 %ebp0xfd2d0 %eip0x8048394 callee: push %ebp mov %esp,%ebp mov 0xc(%ebp),%eax mov 0x8(%ebp),%edx lea (%edx,%eax,1),%eax add $0x1,%eax pop %ebp ret main: push %ebp mov %esp,%ebp sub $0x18,%esp movl $0x28,0x4(%esp) movl $0xa,(%esp) call 0x8048394 mov %eax,-0x4(%ebp) mov -0x4(%ebp),%eax leave ret 0x8048394 0x8048395 0x8048397 0x804839a 0x804839d 0x80483a0 0x80483a3 0x80483a4 0x80483a5 0x80483a6 0x80483a8 0x80483ab 0x80483b3 0x80483ba 0x80483bf 0x80483c2 0x80483c5 0x80483c6 0xfd2d4 0xfd2d0 0xfd2b8 0xfd2bc 0xfd2b4 0xfd2b0
57
Adam Doupé, Principles of Programming Languages 0xfd2c0 0x28 0xa 0x80483bf 0xfd2d0 57 0xFFFFFFFF 0x00000000 %eax %edx %esp0xfd2b0 %ebp0xfd2d0 %eip0x8048394 callee: push %ebp mov %esp,%ebp mov 0xc(%ebp),%eax mov 0x8(%ebp),%edx lea (%edx,%eax,1),%eax add $0x1,%eax pop %ebp ret main: push %ebp mov %esp,%ebp sub $0x18,%esp movl $0x28,0x4(%esp) movl $0xa,(%esp) call 0x8048394 mov %eax,-0x4(%ebp) mov -0x4(%ebp),%eax leave ret 0x8048394 0x8048395 0x8048397 0x804839a 0x804839d 0x80483a0 0x80483a3 0x80483a4 0x80483a5 0x80483a6 0x80483a8 0x80483ab 0x80483b3 0x80483ba 0x80483bf 0x80483c2 0x80483c5 0x80483c6 0xfd2d4 0xfd2d0 0xfd2b8 0xfd2bc 0xfd2b4 0xfd2b0
58
Adam Doupé, Principles of Programming Languages 0xfd2c0 0x28 0xa 0x80483bf 0xfd2d0 58 0xFFFFFFFF 0x00000000 %eax %edx %esp0xfd2b0 %ebp0xfd2d0 %eip0x8048395 callee: push %ebp mov %esp,%ebp mov 0xc(%ebp),%eax mov 0x8(%ebp),%edx lea (%edx,%eax,1),%eax add $0x1,%eax pop %ebp ret main: push %ebp mov %esp,%ebp sub $0x18,%esp movl $0x28,0x4(%esp) movl $0xa,(%esp) call 0x8048394 mov %eax,-0x4(%ebp) mov -0x4(%ebp),%eax leave ret 0x8048394 0x8048395 0x8048397 0x804839a 0x804839d 0x80483a0 0x80483a3 0x80483a4 0x80483a5 0x80483a6 0x80483a8 0x80483ab 0x80483b3 0x80483ba 0x80483bf 0x80483c2 0x80483c5 0x80483c6 0xfd2d4 0xfd2d0 0xfd2b8 0xfd2bc 0xfd2b4 0xfd2b0
59
Adam Doupé, Principles of Programming Languages 0xfd2c0 0x28 0xa 0x80483bf 0xfd2d0 59 0xFFFFFFFF 0x00000000 %eax %edx %esp0xfd2b0 %ebp0xfd2b0 %eip0x8048395 callee: push %ebp mov %esp,%ebp mov 0xc(%ebp),%eax mov 0x8(%ebp),%edx lea (%edx,%eax,1),%eax add $0x1,%eax pop %ebp ret main: push %ebp mov %esp,%ebp sub $0x18,%esp movl $0x28,0x4(%esp) movl $0xa,(%esp) call 0x8048394 mov %eax,-0x4(%ebp) mov -0x4(%ebp),%eax leave ret 0x8048394 0x8048395 0x8048397 0x804839a 0x804839d 0x80483a0 0x80483a3 0x80483a4 0x80483a5 0x80483a6 0x80483a8 0x80483ab 0x80483b3 0x80483ba 0x80483bf 0x80483c2 0x80483c5 0x80483c6 0xfd2d4 0xfd2d0 0xfd2b8 0xfd2bc 0xfd2b4 0xfd2b0
60
Adam Doupé, Principles of Programming Languages 0xfd2c0 0x28 0xa 0x80483bf 0xfd2d0 60 0xFFFFFFFF 0x00000000 %eax %edx %esp0xfd2b0 %ebp0xfd2b0 %eip0x8048397 callee: push %ebp mov %esp,%ebp mov 0xc(%ebp),%eax mov 0x8(%ebp),%edx lea (%edx,%eax,1),%eax add $0x1,%eax pop %ebp ret main: push %ebp mov %esp,%ebp sub $0x18,%esp movl $0x28,0x4(%esp) movl $0xa,(%esp) call 0x8048394 mov %eax,-0x4(%ebp) mov -0x4(%ebp),%eax leave ret 0x8048394 0x8048395 0x8048397 0x804839a 0x804839d 0x80483a0 0x80483a3 0x80483a4 0x80483a5 0x80483a6 0x80483a8 0x80483ab 0x80483b3 0x80483ba 0x80483bf 0x80483c2 0x80483c5 0x80483c6 0xfd2d4 0xfd2d0 0xfd2b8 0xfd2bc 0xfd2b4 0xfd2b0
61
Adam Doupé, Principles of Programming Languages 0xfd2c0 0x28 0xa 0x80483bf 0xfd2d0 61 0xFFFFFFFF 0x00000000 %eax %edx %esp0xfd2b0 %ebp0xfd2b0 %eip0x8048397 callee: push %ebp mov %esp,%ebp mov 0xc(%ebp),%eax mov 0x8(%ebp),%edx lea (%edx,%eax,1),%eax add $0x1,%eax pop %ebp ret main: push %ebp mov %esp,%ebp sub $0x18,%esp movl $0x28,0x4(%esp) movl $0xa,(%esp) call 0x8048394 mov %eax,-0x4(%ebp) mov -0x4(%ebp),%eax leave ret 0x8048394 0x8048395 0x8048397 0x804839a 0x804839d 0x80483a0 0x80483a3 0x80483a4 0x80483a5 0x80483a6 0x80483a8 0x80483ab 0x80483b3 0x80483ba 0x80483bf 0x80483c2 0x80483c5 0x80483c6 0xfd2d4 0xfd2d0 0xfd2b8 0xfd2bc 0xfd2b4 0xfd2b0 maincallee
62
Adam Doupé, Principles of Programming Languages 0xfd2c0 0x28 0xa 0x80483bf 0xfd2d0 62 0xFFFFFFFF 0x00000000 %eax0x28 %edx %esp0xfd2b0 %ebp0xfd2b0 %eip0x8048397 callee: push %ebp mov %esp,%ebp mov 0xc(%ebp),%eax mov 0x8(%ebp),%edx lea (%edx,%eax,1),%eax add $0x1,%eax pop %ebp ret main: push %ebp mov %esp,%ebp sub $0x18,%esp movl $0x28,0x4(%esp) movl $0xa,(%esp) call 0x8048394 mov %eax,-0x4(%ebp) mov -0x4(%ebp),%eax leave ret 0x8048394 0x8048395 0x8048397 0x804839a 0x804839d 0x80483a0 0x80483a3 0x80483a4 0x80483a5 0x80483a6 0x80483a8 0x80483ab 0x80483b3 0x80483ba 0x80483bf 0x80483c2 0x80483c5 0x80483c6 0xfd2d4 0xfd2d0 0xfd2b8 0xfd2bc 0xfd2b4 0xfd2b0
63
Adam Doupé, Principles of Programming Languages 0xfd2c0 0x28 0xa 0x80483bf 0xfd2d0 63 0xFFFFFFFF 0x00000000 %eax0x28 %edx %esp0xfd2b0 %ebp0xfd2b0 %eip0x804839a callee: push %ebp mov %esp,%ebp mov 0xc(%ebp),%eax mov 0x8(%ebp),%edx lea (%edx,%eax,1),%eax add $0x1,%eax pop %ebp ret main: push %ebp mov %esp,%ebp sub $0x18,%esp movl $0x28,0x4(%esp) movl $0xa,(%esp) call 0x8048394 mov %eax,-0x4(%ebp) mov -0x4(%ebp),%eax leave ret 0x8048394 0x8048395 0x8048397 0x804839a 0x804839d 0x80483a0 0x80483a3 0x80483a4 0x80483a5 0x80483a6 0x80483a8 0x80483ab 0x80483b3 0x80483ba 0x80483bf 0x80483c2 0x80483c5 0x80483c6 0xfd2d4 0xfd2d0 0xfd2b8 0xfd2bc 0xfd2b4 0xfd2b0
64
Adam Doupé, Principles of Programming Languages 0xfd2c0 0x28 0xa 0x80483bf 0xfd2d0 64 0xFFFFFFFF 0x00000000 %eax0x28 %edx0xa %esp0xfd2b0 %ebp0xfd2b0 %eip0x804839a callee: push %ebp mov %esp,%ebp mov 0xc(%ebp),%eax mov 0x8(%ebp),%edx lea (%edx,%eax,1),%eax add $0x1,%eax pop %ebp ret main: push %ebp mov %esp,%ebp sub $0x18,%esp movl $0x28,0x4(%esp) movl $0xa,(%esp) call 0x8048394 mov %eax,-0x4(%ebp) mov -0x4(%ebp),%eax leave ret 0x8048394 0x8048395 0x8048397 0x804839a 0x804839d 0x80483a0 0x80483a3 0x80483a4 0x80483a5 0x80483a6 0x80483a8 0x80483ab 0x80483b3 0x80483ba 0x80483bf 0x80483c2 0x80483c5 0x80483c6 0xfd2d4 0xfd2d0 0xfd2b8 0xfd2bc 0xfd2b4 0xfd2b0
65
Adam Doupé, Principles of Programming Languages 0xfd2c0 0x28 0xa 0x80483bf 0xfd2d0 65 0xFFFFFFFF 0x00000000 %eax0x28 %edx0xa %esp0xfd2b0 %ebp0xfd2b0 %eip0x804839d callee: push %ebp mov %esp,%ebp mov 0xc(%ebp),%eax mov 0x8(%ebp),%edx lea (%edx,%eax,1),%eax add $0x1,%eax pop %ebp ret main: push %ebp mov %esp,%ebp sub $0x18,%esp movl $0x28,0x4(%esp) movl $0xa,(%esp) call 0x8048394 mov %eax,-0x4(%ebp) mov -0x4(%ebp),%eax leave ret 0x8048394 0x8048395 0x8048397 0x804839a 0x804839d 0x80483a0 0x80483a3 0x80483a4 0x80483a5 0x80483a6 0x80483a8 0x80483ab 0x80483b3 0x80483ba 0x80483bf 0x80483c2 0x80483c5 0x80483c6 0xfd2d4 0xfd2d0 0xfd2b8 0xfd2bc 0xfd2b4 0xfd2b0
66
Adam Doupé, Principles of Programming Languages 0xfd2c0 0x28 0xa 0x80483bf 0xfd2d0 66 0xFFFFFFFF 0x00000000 %eax0x32 %edx0xa %esp0xfd2b0 %ebp0xfd2b0 %eip0x804839d callee: push %ebp mov %esp,%ebp mov 0xc(%ebp),%eax mov 0x8(%ebp),%edx lea (%edx,%eax,1),%eax add $0x1,%eax pop %ebp ret main: push %ebp mov %esp,%ebp sub $0x18,%esp movl $0x28,0x4(%esp) movl $0xa,(%esp) call 0x8048394 mov %eax,-0x4(%ebp) mov -0x4(%ebp),%eax leave ret 0x8048394 0x8048395 0x8048397 0x804839a 0x804839d 0x80483a0 0x80483a3 0x80483a4 0x80483a5 0x80483a6 0x80483a8 0x80483ab 0x80483b3 0x80483ba 0x80483bf 0x80483c2 0x80483c5 0x80483c6 0xfd2d4 0xfd2d0 0xfd2b8 0xfd2bc 0xfd2b4 0xfd2b0
67
Adam Doupé, Principles of Programming Languages 0xfd2c0 0x28 0xa 0x80483bf 0xfd2d0 67 0xFFFFFFFF 0x00000000 %eax0x32 %edx0xa %esp0xfd2b0 %ebp0xfd2b0 %eip0x80483a0 callee: push %ebp mov %esp,%ebp mov 0xc(%ebp),%eax mov 0x8(%ebp),%edx lea (%edx,%eax,1),%eax add $0x1,%eax pop %ebp ret main: push %ebp mov %esp,%ebp sub $0x18,%esp movl $0x28,0x4(%esp) movl $0xa,(%esp) call 0x8048394 mov %eax,-0x4(%ebp) mov -0x4(%ebp),%eax leave ret 0x8048394 0x8048395 0x8048397 0x804839a 0x804839d 0x80483a0 0x80483a3 0x80483a4 0x80483a5 0x80483a6 0x80483a8 0x80483ab 0x80483b3 0x80483ba 0x80483bf 0x80483c2 0x80483c5 0x80483c6 0xfd2d4 0xfd2d0 0xfd2b8 0xfd2bc 0xfd2b4 0xfd2b0
68
Adam Doupé, Principles of Programming Languages 0xfd2c0 0x28 0xa 0x80483bf 0xfd2d0 68 0xFFFFFFFF 0x00000000 %eax0x33 %edx0xa %esp0xfd2b0 %ebp0xfd2b0 %eip0x80483a0 callee: push %ebp mov %esp,%ebp mov 0xc(%ebp),%eax mov 0x8(%ebp),%edx lea (%edx,%eax,1),%eax add $0x1,%eax pop %ebp ret main: push %ebp mov %esp,%ebp sub $0x18,%esp movl $0x28,0x4(%esp) movl $0xa,(%esp) call 0x8048394 mov %eax,-0x4(%ebp) mov -0x4(%ebp),%eax leave ret 0x8048394 0x8048395 0x8048397 0x804839a 0x804839d 0x80483a0 0x80483a3 0x80483a4 0x80483a5 0x80483a6 0x80483a8 0x80483ab 0x80483b3 0x80483ba 0x80483bf 0x80483c2 0x80483c5 0x80483c6 0xfd2d4 0xfd2d0 0xfd2b8 0xfd2bc 0xfd2b4 0xfd2b0
69
Adam Doupé, Principles of Programming Languages 0xfd2c0 0x28 0xa 0x80483bf 0xfd2d0 69 0xFFFFFFFF 0x00000000 %eax0x33 %edx0xa %esp0xfd2b0 %ebp0xfd2b0 %eip0x80483a3 callee: push %ebp mov %esp,%ebp mov 0xc(%ebp),%eax mov 0x8(%ebp),%edx lea (%edx,%eax,1),%eax add $0x1,%eax pop %ebp ret main: push %ebp mov %esp,%ebp sub $0x18,%esp movl $0x28,0x4(%esp) movl $0xa,(%esp) call 0x8048394 mov %eax,-0x4(%ebp) mov -0x4(%ebp),%eax leave ret 0x8048394 0x8048395 0x8048397 0x804839a 0x804839d 0x80483a0 0x80483a3 0x80483a4 0x80483a5 0x80483a6 0x80483a8 0x80483ab 0x80483b3 0x80483ba 0x80483bf 0x80483c2 0x80483c5 0x80483c6 0xfd2d4 0xfd2d0 0xfd2b8 0xfd2bc 0xfd2b4 0xfd2b0
70
Adam Doupé, Principles of Programming Languages 0xfd2c0 0x28 0xa 0x80483bf 0xfd2d0 70 0xFFFFFFFF 0x00000000 %eax0x33 %edx0xa %esp0xfd2b0 %ebp0xfd2d0 %eip0x80483a3 callee: push %ebp mov %esp,%ebp mov 0xc(%ebp),%eax mov 0x8(%ebp),%edx lea (%edx,%eax,1),%eax add $0x1,%eax pop %ebp ret main: push %ebp mov %esp,%ebp sub $0x18,%esp movl $0x28,0x4(%esp) movl $0xa,(%esp) call 0x8048394 mov %eax,-0x4(%ebp) mov -0x4(%ebp),%eax leave ret 0x8048394 0x8048395 0x8048397 0x804839a 0x804839d 0x80483a0 0x80483a3 0x80483a4 0x80483a5 0x80483a6 0x80483a8 0x80483ab 0x80483b3 0x80483ba 0x80483bf 0x80483c2 0x80483c5 0x80483c6 0xfd2d4 0xfd2d0 0xfd2b8 0xfd2bc 0xfd2b4 0xfd2b0
71
Adam Doupé, Principles of Programming Languages 0xfd2c0 0x28 0xa 0x80483bf 0xfd2d0 71 0xFFFFFFFF 0x00000000 %eax0x33 %edx0xa %esp0xfd2b4 %ebp0xfd2d0 %eip0x80483a3 callee: push %ebp mov %esp,%ebp mov 0xc(%ebp),%eax mov 0x8(%ebp),%edx lea (%edx,%eax,1),%eax add $0x1,%eax pop %ebp ret main: push %ebp mov %esp,%ebp sub $0x18,%esp movl $0x28,0x4(%esp) movl $0xa,(%esp) call 0x8048394 mov %eax,-0x4(%ebp) mov -0x4(%ebp),%eax leave ret 0x8048394 0x8048395 0x8048397 0x804839a 0x804839d 0x80483a0 0x80483a3 0x80483a4 0x80483a5 0x80483a6 0x80483a8 0x80483ab 0x80483b3 0x80483ba 0x80483bf 0x80483c2 0x80483c5 0x80483c6 0xfd2d4 0xfd2d0 0xfd2b8 0xfd2bc 0xfd2b4 0xfd2b0
72
Adam Doupé, Principles of Programming Languages 0xfd2c0 0x28 0xa 0x80483bf 0xfd2d0 72 0xFFFFFFFF 0x00000000 %eax0x33 %edx0xa %esp0xfd2b4 %ebp0xfd2d0 %eip0x80483a3 callee: push %ebp mov %esp,%ebp mov 0xc(%ebp),%eax mov 0x8(%ebp),%edx lea (%edx,%eax,1),%eax add $0x1,%eax pop %ebp ret main: push %ebp mov %esp,%ebp sub $0x18,%esp movl $0x28,0x4(%esp) movl $0xa,(%esp) call 0x8048394 mov %eax,-0x4(%ebp) mov -0x4(%ebp),%eax leave ret 0x8048394 0x8048395 0x8048397 0x804839a 0x804839d 0x80483a0 0x80483a3 0x80483a4 0x80483a5 0x80483a6 0x80483a8 0x80483ab 0x80483b3 0x80483ba 0x80483bf 0x80483c2 0x80483c5 0x80483c6 0xfd2d4 0xfd2d0 0xfd2b8 0xfd2bc 0xfd2b4 0xfd2b0
73
Adam Doupé, Principles of Programming Languages 0xfd2c0 0x28 0xa 0x80483bf 0xfd2d0 73 0xFFFFFFFF 0x00000000 %eax0x33 %edx0xa %esp0xfd2b4 %ebp0xfd2d0 %eip0x80483a4 callee: push %ebp mov %esp,%ebp mov 0xc(%ebp),%eax mov 0x8(%ebp),%edx lea (%edx,%eax,1),%eax add $0x1,%eax pop %ebp ret main: push %ebp mov %esp,%ebp sub $0x18,%esp movl $0x28,0x4(%esp) movl $0xa,(%esp) call 0x8048394 mov %eax,-0x4(%ebp) mov -0x4(%ebp),%eax leave ret 0x8048394 0x8048395 0x8048397 0x804839a 0x804839d 0x80483a0 0x80483a3 0x80483a4 0x80483a5 0x80483a6 0x80483a8 0x80483ab 0x80483b3 0x80483ba 0x80483bf 0x80483c2 0x80483c5 0x80483c6 0xfd2d4 0xfd2d0 0xfd2b8 0xfd2bc 0xfd2b4 0xfd2b0
74
Adam Doupé, Principles of Programming Languages 0xfd2c0 0x28 0xa 0x80483bf 0xfd2d0 74 0xFFFFFFFF 0x00000000 %eax0x33 %edx0xa %esp0xfd2b4 %ebp0xfd2d0 %eip0x80483bf callee: push %ebp mov %esp,%ebp mov 0xc(%ebp),%eax mov 0x8(%ebp),%edx lea (%edx,%eax,1),%eax add $0x1,%eax pop %ebp ret main: push %ebp mov %esp,%ebp sub $0x18,%esp movl $0x28,0x4(%esp) movl $0xa,(%esp) call 0x8048394 mov %eax,-0x4(%ebp) mov -0x4(%ebp),%eax leave ret 0x8048394 0x8048395 0x8048397 0x804839a 0x804839d 0x80483a0 0x80483a3 0x80483a4 0x80483a5 0x80483a6 0x80483a8 0x80483ab 0x80483b3 0x80483ba 0x80483bf 0x80483c2 0x80483c5 0x80483c6 0xfd2d4 0xfd2d0 0xfd2b8 0xfd2bc 0xfd2b4 0xfd2b0
75
Adam Doupé, Principles of Programming Languages 0xfd2c0 0x28 0xa 0x80483bf 0xfd2d0 75 0xFFFFFFFF 0x00000000 %eax0x33 %edx0xa %esp0xfd2b8 %ebp0xfd2d0 %eip0x80483bf callee: push %ebp mov %esp,%ebp mov 0xc(%ebp),%eax mov 0x8(%ebp),%edx lea (%edx,%eax,1),%eax add $0x1,%eax pop %ebp ret main: push %ebp mov %esp,%ebp sub $0x18,%esp movl $0x28,0x4(%esp) movl $0xa,(%esp) call 0x8048394 mov %eax,-0x4(%ebp) mov -0x4(%ebp),%eax leave ret 0x8048394 0x8048395 0x8048397 0x804839a 0x804839d 0x80483a0 0x80483a3 0x80483a4 0x80483a5 0x80483a6 0x80483a8 0x80483ab 0x80483b3 0x80483ba 0x80483bf 0x80483c2 0x80483c5 0x80483c6 0xfd2d4 0xfd2d0 0xfd2b8 0xfd2bc 0xfd2b4 0xfd2b0
76
Adam Doupé, Principles of Programming Languages 0xfd2c0 0x28 0xa 0x80483bf 0xfd2d0 76 0xFFFFFFFF 0x00000000 %eax0x33 %edx0xa %esp0xfd2b8 %ebp0xfd2d0 %eip0x80483bf callee: push %ebp mov %esp,%ebp mov 0xc(%ebp),%eax mov 0x8(%ebp),%edx lea (%edx,%eax,1),%eax add $0x1,%eax pop %ebp ret main: push %ebp mov %esp,%ebp sub $0x18,%esp movl $0x28,0x4(%esp) movl $0xa,(%esp) call 0x8048394 mov %eax,-0x4(%ebp) mov -0x4(%ebp),%eax leave ret 0x8048394 0x8048395 0x8048397 0x804839a 0x804839d 0x80483a0 0x80483a3 0x80483a4 0x80483a5 0x80483a6 0x80483a8 0x80483ab 0x80483b3 0x80483ba 0x80483bf 0x80483c2 0x80483c5 0x80483c6 0xfd2d4 0xfd2d0 0xfd2b8 0xfd2bc 0xfd2b4 0xfd2b0
77
Adam Doupé, Principles of Programming Languages 0xfd2c0 0x28 0xa 0x80483bf 0xfd2d0 77 0xFFFFFFFF 0x00000000 %eax0x33 %edx0xa %esp0xfd2b8 %ebp0xfd2d0 %eip0x80483bf callee: push %ebp mov %esp,%ebp mov 0xc(%ebp),%eax mov 0x8(%ebp),%edx lea (%edx,%eax,1),%eax add $0x1,%eax pop %ebp ret main: push %ebp mov %esp,%ebp sub $0x18,%esp movl $0x28,0x4(%esp) movl $0xa,(%esp) call 0x8048394 mov %eax,-0x4(%ebp) mov -0x4(%ebp),%eax leave ret 0x8048394 0x8048395 0x8048397 0x804839a 0x804839d 0x80483a0 0x80483a3 0x80483a4 0x80483a5 0x80483a6 0x80483a8 0x80483ab 0x80483b3 0x80483ba 0x80483bf 0x80483c2 0x80483c5 0x80483c6 0xfd2d4 0xfd2d0 0xfd2b8 0xfd2bc 0xfd2b4 0xfd2b0
78
Adam Doupé, Principles of Programming Languages 0xfd2c0 0x33 0x28 0xa 0x80483bf 0xfd2d0 78 0xFFFFFFFF 0x00000000 %eax0x33 %edx0xa %esp0xfd2b8 %ebp0xfd2d0 %eip0x80483bf callee: push %ebp mov %esp,%ebp mov 0xc(%ebp),%eax mov 0x8(%ebp),%edx lea (%edx,%eax,1),%eax add $0x1,%eax pop %ebp ret main: push %ebp mov %esp,%ebp sub $0x18,%esp movl $0x28,0x4(%esp) movl $0xa,(%esp) call 0x8048394 mov %eax,-0x4(%ebp) mov -0x4(%ebp),%eax leave ret 0x8048394 0x8048395 0x8048397 0x804839a 0x804839d 0x80483a0 0x80483a3 0x80483a4 0x80483a5 0x80483a6 0x80483a8 0x80483ab 0x80483b3 0x80483ba 0x80483bf 0x80483c2 0x80483c5 0x80483c6 0xfd2d4 0xfd2d0 0xfd2b8 0xfd2bc 0xfd2b4 0xfd2b0 0xfd2cc
79
Adam Doupé, Principles of Programming Languages 0xfd2c0 0x33 0x28 0xa 0x80483bf 0xfd2d0 79 0xFFFFFFFF 0x00000000 %eax0x33 %edx0xa %esp0xfd2b8 %ebp0xfd2d0 %eip0x80483c2 callee: push %ebp mov %esp,%ebp mov 0xc(%ebp),%eax mov 0x8(%ebp),%edx lea (%edx,%eax,1),%eax add $0x1,%eax pop %ebp ret main: push %ebp mov %esp,%ebp sub $0x18,%esp movl $0x28,0x4(%esp) movl $0xa,(%esp) call 0x8048394 mov %eax,-0x4(%ebp) mov -0x4(%ebp),%eax leave ret 0x8048394 0x8048395 0x8048397 0x804839a 0x804839d 0x80483a0 0x80483a3 0x80483a4 0x80483a5 0x80483a6 0x80483a8 0x80483ab 0x80483b3 0x80483ba 0x80483bf 0x80483c2 0x80483c5 0x80483c6 0xfd2d4 0xfd2d0 0xfd2b8 0xfd2bc 0xfd2b4 0xfd2b0 0xfd2cc
80
Adam Doupé, Principles of Programming Languages 0xfd2c0 0x33 0x28 0xa 0x80483bf 0xfd2d0 80 0xFFFFFFFF 0x00000000 %eax0x33 %edx0xa %esp0xfd2b8 %ebp0xfd2d0 %eip0x80483c2 callee: push %ebp mov %esp,%ebp mov 0xc(%ebp),%eax mov 0x8(%ebp),%edx lea (%edx,%eax,1),%eax add $0x1,%eax pop %ebp ret main: push %ebp mov %esp,%ebp sub $0x18,%esp movl $0x28,0x4(%esp) movl $0xa,(%esp) call 0x8048394 mov %eax,-0x4(%ebp) mov -0x4(%ebp),%eax leave ret 0x8048394 0x8048395 0x8048397 0x804839a 0x804839d 0x80483a0 0x80483a3 0x80483a4 0x80483a5 0x80483a6 0x80483a8 0x80483ab 0x80483b3 0x80483ba 0x80483bf 0x80483c2 0x80483c5 0x80483c6 0xfd2d4 0xfd2d0 0xfd2b8 0xfd2bc 0xfd2b4 0xfd2b0 0xfd2cc
81
Adam Doupé, Principles of Programming Languages 0xfd2c0 0x33 0x28 0xa 0x80483bf 0xfd2d0 81 0xFFFFFFFF 0x00000000 %eax0x33 %edx0xa %esp0xfd2b8 %ebp0xfd2d0 %eip0x80483c5 callee: push %ebp mov %esp,%ebp mov 0xc(%ebp),%eax mov 0x8(%ebp),%edx lea (%edx,%eax,1),%eax add $0x1,%eax pop %ebp ret main: push %ebp mov %esp,%ebp sub $0x18,%esp movl $0x28,0x4(%esp) movl $0xa,(%esp) call 0x8048394 mov %eax,-0x4(%ebp) mov -0x4(%ebp),%eax leave ret 0x8048394 0x8048395 0x8048397 0x804839a 0x804839d 0x80483a0 0x80483a3 0x80483a4 0x80483a5 0x80483a6 0x80483a8 0x80483ab 0x80483b3 0x80483ba 0x80483bf 0x80483c2 0x80483c5 0x80483c6 0xfd2d4 0xfd2d0 0xfd2b8 0xfd2bc 0xfd2b4 0xfd2b0 0xfd2cc
82
Adam Doupé, Principles of Programming Languages 0xfd2c0 0x33 0x28 0xa 0x80483bf 0xfd2d0 82 0xFFFFFFFF 0x00000000 %eax0x33 %edx0xa %esp0xfd2d0 %ebp0xfd2d0 %eip0x80483c5 callee: push %ebp mov %esp,%ebp mov 0xc(%ebp),%eax mov 0x8(%ebp),%edx lea (%edx,%eax,1),%eax add $0x1,%eax pop %ebp ret main: push %ebp mov %esp,%ebp sub $0x18,%esp movl $0x28,0x4(%esp) movl $0xa,(%esp) call 0x8048394 mov %eax,-0x4(%ebp) mov -0x4(%ebp),%eax leave ret 0x8048394 0x8048395 0x8048397 0x804839a 0x804839d 0x80483a0 0x80483a3 0x80483a4 0x80483a5 0x80483a6 0x80483a8 0x80483ab 0x80483b3 0x80483ba 0x80483bf 0x80483c2 0x80483c5 0x80483c6 0xfd2d4 0xfd2d0 0xfd2b8 0xfd2bc 0xfd2b4 0xfd2b0 0xfd2cc
83
Adam Doupé, Principles of Programming Languages 0xfd2c0 0x33 0x28 0xa 0x80483bf 0xfd2d0 83 0xFFFFFFFF 0x00000000 %eax0x33 %edx0xa %esp0xfd2d0 %ebp0xfd2c0 %eip0x80483c5 callee: push %ebp mov %esp,%ebp mov 0xc(%ebp),%eax mov 0x8(%ebp),%edx lea (%edx,%eax,1),%eax add $0x1,%eax pop %ebp ret main: push %ebp mov %esp,%ebp sub $0x18,%esp movl $0x28,0x4(%esp) movl $0xa,(%esp) call 0x8048394 mov %eax,-0x4(%ebp) mov -0x4(%ebp),%eax leave ret 0x8048394 0x8048395 0x8048397 0x804839a 0x804839d 0x80483a0 0x80483a3 0x80483a4 0x80483a5 0x80483a6 0x80483a8 0x80483ab 0x80483b3 0x80483ba 0x80483bf 0x80483c2 0x80483c5 0x80483c6 0xfd2d4 0xfd2d0 0xfd2b8 0xfd2bc 0xfd2b4 0xfd2b0 0xfd2cc
84
Adam Doupé, Principles of Programming Languages 0xfd2c0 0x33 0x28 0xa 0x80483bf 0xfd2d0 84 0xFFFFFFFF 0x00000000 %eax0x33 %edx0xa %esp0xfd2d4 %ebp0xfd2c0 %eip0x80483c5 callee: push %ebp mov %esp,%ebp mov 0xc(%ebp),%eax mov 0x8(%ebp),%edx lea (%edx,%eax,1),%eax add $0x1,%eax pop %ebp ret main: push %ebp mov %esp,%ebp sub $0x18,%esp movl $0x28,0x4(%esp) movl $0xa,(%esp) call 0x8048394 mov %eax,-0x4(%ebp) mov -0x4(%ebp),%eax leave ret 0x8048394 0x8048395 0x8048397 0x804839a 0x804839d 0x80483a0 0x80483a3 0x80483a4 0x80483a5 0x80483a6 0x80483a8 0x80483ab 0x80483b3 0x80483ba 0x80483bf 0x80483c2 0x80483c5 0x80483c6 0xfd2d4 0xfd2d0 0xfd2b8 0xfd2bc 0xfd2b4 0xfd2b0 0xfd2cc
85
Adam Doupé, Principles of Programming Languages 0xfd2c0 0x33 0x28 0xa 0x80483bf 0xfd2d0 85 0xFFFFFFFF 0x00000000 %eax0x33 %edx0xa %esp0xfd2d4 %ebp0xfd2c0 %eip0x80483c5 callee: push %ebp mov %esp,%ebp mov 0xc(%ebp),%eax mov 0x8(%ebp),%edx lea (%edx,%eax,1),%eax add $0x1,%eax pop %ebp ret main: push %ebp mov %esp,%ebp sub $0x18,%esp movl $0x28,0x4(%esp) movl $0xa,(%esp) call 0x8048394 mov %eax,-0x4(%ebp) mov -0x4(%ebp),%eax leave ret 0x8048394 0x8048395 0x8048397 0x804839a 0x804839d 0x80483a0 0x80483a3 0x80483a4 0x80483a5 0x80483a6 0x80483a8 0x80483ab 0x80483b3 0x80483ba 0x80483bf 0x80483c2 0x80483c5 0x80483c6 0xfd2d4 0xfd2d0 0xfd2b8 0xfd2bc 0xfd2b4 0xfd2b0 0xfd2cc
86
Adam Doupé, Principles of Programming Languages 0xfd2c0 0x33 0x28 0xa 0x80483bf 0xfd2d0 86 0xFFFFFFFF 0x00000000 %eax0x33 %edx0xa %esp0xfd2d4 %ebp0xfd2c0 %eip0x80483c6 callee: push %ebp mov %esp,%ebp mov 0xc(%ebp),%eax mov 0x8(%ebp),%edx lea (%edx,%eax,1),%eax add $0x1,%eax pop %ebp ret main: push %ebp mov %esp,%ebp sub $0x18,%esp movl $0x28,0x4(%esp) movl $0xa,(%esp) call 0x8048394 mov %eax,-0x4(%ebp) mov -0x4(%ebp),%eax leave ret 0x8048394 0x8048395 0x8048397 0x804839a 0x804839d 0x80483a0 0x80483a3 0x80483a4 0x80483a5 0x80483a6 0x80483a8 0x80483ab 0x80483b3 0x80483ba 0x80483bf 0x80483c2 0x80483c5 0x80483c6 0xfd2d4 0xfd2d0 0xfd2b8 0xfd2bc 0xfd2b4 0xfd2b0 0xfd2cc
87
Adam Doupé, Principles of Programming Languages Function Parameter Passing How did the previous example pass parameters to the function callee? –Pushed the values onto the stack What are the semantics of passing parameters to a function? Multiple approaches –Pass by value –Pass by reference –Pass by name 87
88
Adam Doupé, Principles of Programming Languages Pass by Value Values of the actual parameters at function invocation are calculated and then copied to the function –We have seen how this is done for C, a copy of the values are placed on the stack 88
89
Adam Doupé, Principles of Programming Languages #include int x; void test(int x) { x = x + 5; printf("%d\n", x); } int main() { int y = 4; test(y); printf("%d\n", y); return y; } 89 [adamd@ragnuk]$ gcc –Wall pass_by_value.c [adamd@ragnuk]$./a.out 9 4 y 4 x 4 9
90
Adam Doupé, Principles of Programming Languages Pass by Reference The formal parameters are bound to the locations associated with the actual parameters –Thus, the actual parameters must be l-values 90
91
Adam Doupé, Principles of Programming Languages #include int x; void test(int& x) { x = x + 5; printf("%d\n", x); } int main() { int y = 4; test(y); printf("%d\n", y); return y; } 91 [adamd@ragnuk]$ g++ –Wall pass_by_value.c [adamd@ragnuk]$./a.out 9 9 x y 49
92
Adam Doupé, Principles of Programming Languages Pass by name The formal parameters are replaced by the text of the actual parameters everywhere in the fucntion that the formal parameters occur 92
93
Adam Doupé, Principles of Programming Languages #include int x; void test(int x) { x = x + 5; printf("%d\n", x); } int main() { int y = 4; test(y); printf("%d\n", y); return y; } void test(int y) { y = y + 5; printf("%d\n", y); } 93 [adamd@ragnuk]$ gcc –Wall pass_by_name_1.c [adamd@ragnuk]$./a.out 9 9
94
Adam Doupé, Principles of Programming Languages #include int i; int a[10]; void inc(int x) { i++; x++; } int main() { i = 1; a[1] = 1; a[2] = 2; inc(a[i]); printf("%d\n%d\n%d\n", i, a[1], a[2]); return 0; } void inc(int a[i]) { i++; a[i]++; } 94 [adamd@ragnuk]$ gcc –Wall pass_by_name_2.c [adamd@ragnuk]$./a.out 2 1 3
95
Adam Doupé, Principles of Programming Languages #include int i; int p(int y) { int j = y; i++; return j + y; } void q() { int j = 2; i = 0; printf("%d\n", p(i+j)); } int main() { q(); return 0; } int p(int (i+j)) { int j = (i+j); i++; return j + (i+j); } 95 [adamd@ragnuk]$ gcc –Wall pass_by_name_3.c [adamd@ragnuk]$./a.out 5
96
Adam Doupé, Principles of Programming Languages #include int foo(int test) { return 10; } int main() { int a = 0; int b = foo(a++); printf("%d\n%d\n", a, b); return 0; } int foo(int a++) { return 10; } 96 [adamd@ragnuk]$ gcc –Wall pass_by_name_4.c [adamd@ragnuk]$./a.out 0 10
97
Adam Doupé, Principles of Programming Languages #include int i; int p(int y) { int j = y; i++; return j + y; } void q() { int j = 2; i = 0; printf("%d\n", p(i+j)); } int main() { q(); return 0; } #include int i, j; int i_plus_j() { return i+j; } int p(int (*y)(void)) { int j = y(); i++; return j + y(); } void q() { j = 2; i = 0; printf("%d\n", p(i_plus_j)); } int main() { q(); return 0; } 97 [adamd@ragnuk]$ gcc –Wall pass_by_name_simulation.c [adamd@ragnuk]$./a.out 5
98
Adam Doupé, Principles of Programming Languages Java What is the parameter passing semantics of Java? –Pass by value? –Pass by reference? –Pass by name? 98
99
Adam Doupé, Principles of Programming Languages class Testing { int foo; } public class ParameterPassing { public static void main(String [] args) { Testing bar = new Testing(); Testing snap = new Testing(); bar.foo = 0; snap.foo = 10; PassByQuestionMark(bar, snap); System.out.println(bar.foo + "\n" + snap.foo); } public static void PassByQuestionMark(Testing a, Testing b) { b = new Testing(); b.foo = 100; a.foo = 42; } } 99
100
Adam Doupé, Principles of Programming Languages Java Essentially pass by value and assignment share semantics Note that this is not standard terminology How is it implemented under-the-hood? 100
101
Adam Doupé, Principles of Programming Languages Implications of Cdecl Saved EBP and saved EIP are stored on the stack What prevents a program/function from writing/changing those values? –What would happen if they did? 101
102
Adam Doupé, Principles of Programming Languages #include void mycpy(char* str) { char foo[4]; strcpy(foo, str); } int main() { callee("asu cse 340 fall 2015 rocks!"); printf("After"); return 0; } 102 mycpy: push %ebp mov %esp,%ebp sub $0x28,%esp mov 0x8(%ebp),%eax mov %eax,0x4(%esp) lea -0xc(%ebp),%eax mov %eax,(%esp) call strcpy leave ret main: push %ebp mov %esp,%ebp sub $0x10,%esp movl $0x8048504,(%esp) call mycpy mov $0x8048517,%eax mov %eax,(%esp) call printf mov $0x0,%eax leave ret
103
Adam Doupé, Principles of Programming Languages 103 0xFFFFFFFF 0x00000000 0xfd2d4 %eax %esp0xfd2d4 %ebp0xfd2e0 %eip0x804840e mycpy: push %ebp mov %esp,%ebp sub $0x28,%esp mov 0x8(%ebp),%eax mov %eax,0x4(%esp) lea -0xc(%ebp),%eax mov %eax,(%esp) call strcpy leave ret main: push %ebp mov %esp,%ebp sub $0x10,%esp movl $0x8048504,(%esp) call mycpy mov $0x8048517,%eax mov %eax,(%esp) call printf mov $0x0,%eax leave ret 0x80483f4 0x80483f5 0x80483f7 0x80483fa 0x80483fd 0x8048401 0x8048404 0x8048407 0x804840c 0x804840d 0x804840e 0x804840f 0x8048414 0x8048417 0x804841e 0x8048423 0x8048428 0x804842b 0x8048430 0x8048435 0x8048436
104
Adam Doupé, Principles of Programming Languages 0xfd2e0 104 0xFFFFFFFF 0x00000000 0xfd2d4 %eax %esp0xfd2d0 %ebp0xfd2e0 %eip0x804840e mycpy: push %ebp mov %esp,%ebp sub $0x28,%esp mov 0x8(%ebp),%eax mov %eax,0x4(%esp) lea -0xc(%ebp),%eax mov %eax,(%esp) call strcpy leave ret main: push %ebp mov %esp,%ebp sub $0x10,%esp movl $0x8048504,(%esp) call mycpy mov $0x8048517,%eax mov %eax,(%esp) call printf mov $0x0,%eax leave ret 0x80483f4 0x80483f5 0x80483f7 0x80483fa 0x80483fd 0x8048401 0x8048404 0x8048407 0x804840c 0x804840d 0x804840e 0x804840f 0x8048414 0x8048417 0x804841e 0x8048423 0x8048428 0x804842b 0x8048430 0x8048435 0x8048436
105
Adam Doupé, Principles of Programming Languages 0xfd2e0 105 0xFFFFFFFF 0x00000000 0xfd2d4 %eax %esp0xfd2d0 %ebp0xfd2e0 %eip0x804840f mycpy: push %ebp mov %esp,%ebp sub $0x28,%esp mov 0x8(%ebp),%eax mov %eax,0x4(%esp) lea -0xc(%ebp),%eax mov %eax,(%esp) call strcpy leave ret main: push %ebp mov %esp,%ebp sub $0x10,%esp movl $0x8048504,(%esp) call mycpy mov $0x8048517,%eax mov %eax,(%esp) call printf mov $0x0,%eax leave ret 0x80483f4 0x80483f5 0x80483f7 0x80483fa 0x80483fd 0x8048401 0x8048404 0x8048407 0x804840c 0x804840d 0x804840e 0x804840f 0x8048414 0x8048417 0x804841e 0x8048423 0x8048428 0x804842b 0x8048430 0x8048435 0x8048436
106
Adam Doupé, Principles of Programming Languages 0xfd2e0 106 0xFFFFFFFF 0x00000000 0xfd2d4 %eax %esp0xfd2d0 %ebp0xfd2d0 %eip0x804840f mycpy: push %ebp mov %esp,%ebp sub $0x28,%esp mov 0x8(%ebp),%eax mov %eax,0x4(%esp) lea -0xc(%ebp),%eax mov %eax,(%esp) call strcpy leave ret main: push %ebp mov %esp,%ebp sub $0x10,%esp movl $0x8048504,(%esp) call mycpy mov $0x8048517,%eax mov %eax,(%esp) call printf mov $0x0,%eax leave ret 0x80483f4 0x80483f5 0x80483f7 0x80483fa 0x80483fd 0x8048401 0x8048404 0x8048407 0x804840c 0x804840d 0x804840e 0x804840f 0x8048414 0x8048417 0x804841e 0x8048423 0x8048428 0x804842b 0x8048430 0x8048435 0x8048436
107
Adam Doupé, Principles of Programming Languages 0xfd2e0 107 0xFFFFFFFF 0x00000000 0xfd2d4 %eax %esp0xfd2d0 %ebp0xfd2d0 %eip0x8048414 mycpy: push %ebp mov %esp,%ebp sub $0x28,%esp mov 0x8(%ebp),%eax mov %eax,0x4(%esp) lea -0xc(%ebp),%eax mov %eax,(%esp) call strcpy leave ret main: push %ebp mov %esp,%ebp sub $0x10,%esp movl $0x8048504,(%esp) call mycpy mov $0x8048517,%eax mov %eax,(%esp) call printf mov $0x0,%eax leave ret 0x80483f4 0x80483f5 0x80483f7 0x80483fa 0x80483fd 0x8048401 0x8048404 0x8048407 0x804840c 0x804840d 0x804840e 0x804840f 0x8048414 0x8048417 0x804841e 0x8048423 0x8048428 0x804842b 0x8048430 0x8048435 0x8048436
108
Adam Doupé, Principles of Programming Languages 0xfd2e0 108 0xFFFFFFFF 0x00000000 0xfd2d4 %eax %esp0xfd2c0 %ebp0xfd2d0 %eip0x8048414 mycpy: push %ebp mov %esp,%ebp sub $0x28,%esp mov 0x8(%ebp),%eax mov %eax,0x4(%esp) lea -0xc(%ebp),%eax mov %eax,(%esp) call strcpy leave ret main: push %ebp mov %esp,%ebp sub $0x10,%esp movl $0x8048504,(%esp) call mycpy mov $0x8048517,%eax mov %eax,(%esp) call printf mov $0x0,%eax leave ret 0x80483f4 0x80483f5 0x80483f7 0x80483fa 0x80483fd 0x8048401 0x8048404 0x8048407 0x804840c 0x804840d 0x804840e 0x804840f 0x8048414 0x8048417 0x804841e 0x8048423 0x8048428 0x804842b 0x8048430 0x8048435 0x8048436 0xfd2c0
109
Adam Doupé, Principles of Programming Languages 0xfd2e0 109 0xFFFFFFFF 0x00000000 0xfd2d4 %eax %esp0xfd2c0 %ebp0xfd2d0 %eip0x8048417 mycpy: push %ebp mov %esp,%ebp sub $0x28,%esp mov 0x8(%ebp),%eax mov %eax,0x4(%esp) lea -0xc(%ebp),%eax mov %eax,(%esp) call strcpy leave ret main: push %ebp mov %esp,%ebp sub $0x10,%esp movl $0x8048504,(%esp) call mycpy mov $0x8048517,%eax mov %eax,(%esp) call printf mov $0x0,%eax leave ret 0x80483f4 0x80483f5 0x80483f7 0x80483fa 0x80483fd 0x8048401 0x8048404 0x8048407 0x804840c 0x804840d 0x804840e 0x804840f 0x8048414 0x8048417 0x804841e 0x8048423 0x8048428 0x804842b 0x8048430 0x8048435 0x8048436 0xfd2c0
110
Adam Doupé, Principles of Programming Languages 0xfd2e0 0x8048504 110 0xFFFFFFFF 0x00000000 0xfd2d4 %eax %esp0xfd2c0 %ebp0xfd2d0 %eip0x8048417 mycpy: push %ebp mov %esp,%ebp sub $0x28,%esp mov 0x8(%ebp),%eax mov %eax,0x4(%esp) lea -0xc(%ebp),%eax mov %eax,(%esp) call strcpy leave ret main: push %ebp mov %esp,%ebp sub $0x10,%esp movl $0x8048504,(%esp) call mycpy mov $0x8048517,%eax mov %eax,(%esp) call printf mov $0x0,%eax leave ret 0x80483f4 0x80483f5 0x80483f7 0x80483fa 0x80483fd 0x8048401 0x8048404 0x8048407 0x804840c 0x804840d 0x804840e 0x804840f 0x8048414 0x8048417 0x804841e 0x8048423 0x8048428 0x804842b 0x8048430 0x8048435 0x8048436 0xfd2c0
111
Adam Doupé, Principles of Programming Languages 0xfd2e0 0x8048504 111 0xFFFFFFFF 0x00000000 0xfd2d4 %eax %esp0xfd2c0 %ebp0xfd2d0 %eip0x804841e mycpy: push %ebp mov %esp,%ebp sub $0x28,%esp mov 0x8(%ebp),%eax mov %eax,0x4(%esp) lea -0xc(%ebp),%eax mov %eax,(%esp) call strcpy leave ret main: push %ebp mov %esp,%ebp sub $0x10,%esp movl $0x8048504,(%esp) call mycpy mov $0x8048517,%eax mov %eax,(%esp) call printf mov $0x0,%eax leave ret 0x80483f4 0x80483f5 0x80483f7 0x80483fa 0x80483fd 0x8048401 0x8048404 0x8048407 0x804840c 0x804840d 0x804840e 0x804840f 0x8048414 0x8048417 0x804841e 0x8048423 0x8048428 0x804842b 0x8048430 0x8048435 0x8048436 0xfd2c0
112
Adam Doupé, Principles of Programming Languages 0xfd2e0 0x8048504 0x8048423 112 0xFFFFFFFF 0x00000000 0xfd2d4 %eax %esp0xfd2bc %ebp0xfd2d0 %eip0x80483f4 mycpy: push %ebp mov %esp,%ebp sub $0x28,%esp mov 0x8(%ebp),%eax mov %eax,0x4(%esp) lea -0xc(%ebp),%eax mov %eax,(%esp) call strcpy leave ret main: push %ebp mov %esp,%ebp sub $0x10,%esp movl $0x8048504,(%esp) call mycpy mov $0x8048517,%eax mov %eax,(%esp) call printf mov $0x0,%eax leave ret 0x80483f4 0x80483f5 0x80483f7 0x80483fa 0x80483fd 0x8048401 0x8048404 0x8048407 0x804840c 0x804840d 0x804840e 0x804840f 0x8048414 0x8048417 0x804841e 0x8048423 0x8048428 0x804842b 0x8048430 0x8048435 0x8048436 0xfd2c0 0xfd2bc
113
Adam Doupé, Principles of Programming Languages 0xfd2e0 0x8048504 0x8048423 0xfd2d0 113 0xFFFFFFFF 0x00000000 0xfd2d4 %eax %esp0xfd2b8 %ebp0xfd2d0 %eip0x80483f4 mycpy: push %ebp mov %esp,%ebp sub $0x28,%esp mov 0x8(%ebp),%eax mov %eax,0x4(%esp) lea -0xc(%ebp),%eax mov %eax,(%esp) call strcpy leave ret main: push %ebp mov %esp,%ebp sub $0x10,%esp movl $0x8048504,(%esp) call mycpy mov $0x8048517,%eax mov %eax,(%esp) call printf mov $0x0,%eax leave ret 0x80483f4 0x80483f5 0x80483f7 0x80483fa 0x80483fd 0x8048401 0x8048404 0x8048407 0x804840c 0x804840d 0x804840e 0x804840f 0x8048414 0x8048417 0x804841e 0x8048423 0x8048428 0x804842b 0x8048430 0x8048435 0x8048436 0xfd2c0 0xfd2bc 0xfd2b8
114
Adam Doupé, Principles of Programming Languages 0xfd2e0 0x8048504 0x8048423 0xfd2d0 114 0xFFFFFFFF 0x00000000 0xfd2d4 %eax %esp0xfd2b8 %ebp0xfd2d0 %eip0x80483f5 mycpy: push %ebp mov %esp,%ebp sub $0x28,%esp mov 0x8(%ebp),%eax mov %eax,0x4(%esp) lea -0xc(%ebp),%eax mov %eax,(%esp) call strcpy leave ret main: push %ebp mov %esp,%ebp sub $0x10,%esp movl $0x8048504,(%esp) call mycpy mov $0x8048517,%eax mov %eax,(%esp) call printf mov $0x0,%eax leave ret 0x80483f4 0x80483f5 0x80483f7 0x80483fa 0x80483fd 0x8048401 0x8048404 0x8048407 0x804840c 0x804840d 0x804840e 0x804840f 0x8048414 0x8048417 0x804841e 0x8048423 0x8048428 0x804842b 0x8048430 0x8048435 0x8048436 0xfd2c0 0xfd2bc 0xfd2b8
115
Adam Doupé, Principles of Programming Languages 0xfd2e0 0x8048504 0x8048423 0xfd2d0 115 0xFFFFFFFF 0x00000000 0xfd2d4 %eax %esp0xfd2b8 %ebp0xfd2b8 %eip0x80483f5 mycpy: push %ebp mov %esp,%ebp sub $0x28,%esp mov 0x8(%ebp),%eax mov %eax,0x4(%esp) lea -0xc(%ebp),%eax mov %eax,(%esp) call strcpy leave ret main: push %ebp mov %esp,%ebp sub $0x10,%esp movl $0x8048504,(%esp) call mycpy mov $0x8048517,%eax mov %eax,(%esp) call printf mov $0x0,%eax leave ret 0x80483f4 0x80483f5 0x80483f7 0x80483fa 0x80483fd 0x8048401 0x8048404 0x8048407 0x804840c 0x804840d 0x804840e 0x804840f 0x8048414 0x8048417 0x804841e 0x8048423 0x8048428 0x804842b 0x8048430 0x8048435 0x8048436 0xfd2c0 0xfd2bc 0xfd2b8
116
Adam Doupé, Principles of Programming Languages 0xfd2e0 0x8048504 0x8048423 0xfd2d0 116 0xfd2d4 %eax %esp0xfd2b8 %ebp0xfd2b8 %eip0x80483f7 mycpy: push %ebp mov %esp,%ebp sub $0x28,%esp mov 0x8(%ebp),%eax mov %eax,0x4(%esp) lea -0xc(%ebp),%eax mov %eax,(%esp) call strcpy leave ret main: push %ebp mov %esp,%ebp sub $0x10,%esp movl $0x8048504,(%esp) call mycpy mov $0x8048517,%eax mov %eax,(%esp) call printf mov $0x0,%eax leave ret 0x80483f4 0x80483f5 0x80483f7 0x80483fa 0x80483fd 0x8048401 0x8048404 0x8048407 0x804840c 0x804840d 0x804840e 0x804840f 0x8048414 0x8048417 0x804841e 0x8048423 0x8048428 0x804842b 0x8048430 0x8048435 0x8048436 0xfd2c0 0xfd2bc 0xfd2b8
117
Adam Doupé, Principles of Programming Languages 0xfd2e0 0x8048504 0x8048423 0xfd2d0 117 0xfd2d4 %eax %esp0xfd290 %ebp0xfd2b8 %eip0x80483f7 mycpy: push %ebp mov %esp,%ebp sub $0x28,%esp mov 0x8(%ebp),%eax mov %eax,0x4(%esp) lea -0xc(%ebp),%eax mov %eax,(%esp) call strcpy leave ret main: push %ebp mov %esp,%ebp sub $0x10,%esp movl $0x8048504,(%esp) call mycpy mov $0x8048517,%eax mov %eax,(%esp) call printf mov $0x0,%eax leave ret 0x80483f4 0x80483f5 0x80483f7 0x80483fa 0x80483fd 0x8048401 0x8048404 0x8048407 0x804840c 0x804840d 0x804840e 0x804840f 0x8048414 0x8048417 0x804841e 0x8048423 0x8048428 0x804842b 0x8048430 0x8048435 0x8048436 0xfd2c0 0xfd2bc 0xfd2b8 0xfd290
118
Adam Doupé, Principles of Programming Languages 0xfd2e0 0x8048504 0x8048423 0xfd2d0 118 0xfd2d4 %eax %esp0xfd290 %ebp0xfd2b8 %eip0x80483fa mycpy: push %ebp mov %esp,%ebp sub $0x28,%esp mov 0x8(%ebp),%eax mov %eax,0x4(%esp) lea -0xc(%ebp),%eax mov %eax,(%esp) call strcpy leave ret main: push %ebp mov %esp,%ebp sub $0x10,%esp movl $0x8048504,(%esp) call mycpy mov $0x8048517,%eax mov %eax,(%esp) call printf mov $0x0,%eax leave ret 0x80483f4 0x80483f5 0x80483f7 0x80483fa 0x80483fd 0x8048401 0x8048404 0x8048407 0x804840c 0x804840d 0x804840e 0x804840f 0x8048414 0x8048417 0x804841e 0x8048423 0x8048428 0x804842b 0x8048430 0x8048435 0x8048436 0xfd2c0 0xfd2bc 0xfd2b8 0xfd290
119
Adam Doupé, Principles of Programming Languages 0xfd2e0 0x8048504 0x8048423 0xfd2d0 119 0xfd2d4 %eax0x8048504 %esp0xfd290 %ebp0xfd2b8 %eip0x80483fa mycpy: push %ebp mov %esp,%ebp sub $0x28,%esp mov 0x8(%ebp),%eax mov %eax,0x4(%esp) lea -0xc(%ebp),%eax mov %eax,(%esp) call strcpy leave ret main: push %ebp mov %esp,%ebp sub $0x10,%esp movl $0x8048504,(%esp) call mycpy mov $0x8048517,%eax mov %eax,(%esp) call printf mov $0x0,%eax leave ret 0x80483f4 0x80483f5 0x80483f7 0x80483fa 0x80483fd 0x8048401 0x8048404 0x8048407 0x804840c 0x804840d 0x804840e 0x804840f 0x8048414 0x8048417 0x804841e 0x8048423 0x8048428 0x804842b 0x8048430 0x8048435 0x8048436 0xfd2c0 0xfd2bc 0xfd2b8 0xfd290
120
Adam Doupé, Principles of Programming Languages 0xfd2e0 0x8048504 0x8048423 0xfd2d0 120 0xfd2d4 %eax0x8048504 %esp0xfd290 %ebp0xfd2b8 %eip0x80483fd mycpy: push %ebp mov %esp,%ebp sub $0x28,%esp mov 0x8(%ebp),%eax mov %eax,0x4(%esp) lea -0xc(%ebp),%eax mov %eax,(%esp) call strcpy leave ret main: push %ebp mov %esp,%ebp sub $0x10,%esp movl $0x8048504,(%esp) call mycpy mov $0x8048517,%eax mov %eax,(%esp) call printf mov $0x0,%eax leave ret 0x80483f4 0x80483f5 0x80483f7 0x80483fa 0x80483fd 0x8048401 0x8048404 0x8048407 0x804840c 0x804840d 0x804840e 0x804840f 0x8048414 0x8048417 0x804841e 0x8048423 0x8048428 0x804842b 0x8048430 0x8048435 0x8048436 0xfd2c0 0xfd2bc 0xfd2b8 0xfd290
121
Adam Doupé, Principles of Programming Languages 0xfd2e0 0x8048504 0x8048423 0xfd2d0 0x8048504 121 0xfd2d4 %eax0x8048504 %esp0xfd290 %ebp0xfd2b8 %eip0x80483fd mycpy: push %ebp mov %esp,%ebp sub $0x28,%esp mov 0x8(%ebp),%eax mov %eax,0x4(%esp) lea -0xc(%ebp),%eax mov %eax,(%esp) call strcpy leave ret main: push %ebp mov %esp,%ebp sub $0x10,%esp movl $0x8048504,(%esp) call mycpy mov $0x8048517,%eax mov %eax,(%esp) call printf mov $0x0,%eax leave ret 0x80483f4 0x80483f5 0x80483f7 0x80483fa 0x80483fd 0x8048401 0x8048404 0x8048407 0x804840c 0x804840d 0x804840e 0x804840f 0x8048414 0x8048417 0x804841e 0x8048423 0x8048428 0x804842b 0x8048430 0x8048435 0x8048436 0xfd2c0 0xfd2bc 0xfd2b8 0xfd290
122
Adam Doupé, Principles of Programming Languages 0xfd2e0 0x8048504 0x8048423 0xfd2d0 0x8048504 122 0xfd2d4 %eax0xfd2ac %esp0xfd290 %ebp0xfd2b8 %eip0x8048401 mycpy: push %ebp mov %esp,%ebp sub $0x28,%esp mov 0x8(%ebp),%eax mov %eax,0x4(%esp) lea -0xc(%ebp),%eax mov %eax,(%esp) call strcpy leave ret main: push %ebp mov %esp,%ebp sub $0x10,%esp movl $0x8048504,(%esp) call mycpy mov $0x8048517,%eax mov %eax,(%esp) call printf mov $0x0,%eax leave ret 0x80483f4 0x80483f5 0x80483f7 0x80483fa 0x80483fd 0x8048401 0x8048404 0x8048407 0x804840c 0x804840d 0x804840e 0x804840f 0x8048414 0x8048417 0x804841e 0x8048423 0x8048428 0x804842b 0x8048430 0x8048435 0x8048436 0xfd2c0 0xfd2bc 0xfd2b8 0xfd290 0xfd2ac
123
Adam Doupé, Principles of Programming Languages 0xfd2e0 0x8048504 0x8048423 0xfd2d0 0x8048504 123 0xfd2d4 %eax0xfd2ac %esp0xfd290 %ebp0xfd2b8 %eip0x8048404 mycpy: push %ebp mov %esp,%ebp sub $0x28,%esp mov 0x8(%ebp),%eax mov %eax,0x4(%esp) lea -0xc(%ebp),%eax mov %eax,(%esp) call strcpy leave ret main: push %ebp mov %esp,%ebp sub $0x10,%esp movl $0x8048504,(%esp) call mycpy mov $0x8048517,%eax mov %eax,(%esp) call printf mov $0x0,%eax leave ret 0x80483f4 0x80483f5 0x80483f7 0x80483fa 0x80483fd 0x8048401 0x8048404 0x8048407 0x804840c 0x804840d 0x804840e 0x804840f 0x8048414 0x8048417 0x804841e 0x8048423 0x8048428 0x804842b 0x8048430 0x8048435 0x8048436 0xfd2c0 0xfd2bc 0xfd2b8 0xfd290 0xfd2ac
124
Adam Doupé, Principles of Programming Languages 0xfd2e0 0x8048504 0x8048423 0xfd2d0 0x8048504 0xfd2ac 124 0xfd2d4 %eax0xfd2ac %esp0xfd290 %ebp0xfd2b8 %eip0x8048404 mycpy: push %ebp mov %esp,%ebp sub $0x28,%esp mov 0x8(%ebp),%eax mov %eax,0x4(%esp) lea -0xc(%ebp),%eax mov %eax,(%esp) call strcpy leave ret main: push %ebp mov %esp,%ebp sub $0x10,%esp movl $0x8048504,(%esp) call mycpy mov $0x8048517,%eax mov %eax,(%esp) call printf mov $0x0,%eax leave ret 0x80483f4 0x80483f5 0x80483f7 0x80483fa 0x80483fd 0x8048401 0x8048404 0x8048407 0x804840c 0x804840d 0x804840e 0x804840f 0x8048414 0x8048417 0x804841e 0x8048423 0x8048428 0x804842b 0x8048430 0x8048435 0x8048436 0xfd2c0 0xfd2bc 0xfd2b8 0xfd290 0xfd2ac
125
Adam Doupé, Principles of Programming Languages 0xfd2e0 0x8048504 0x8048423 0xfd2d0 0x8048504 0xfd2ac 125 0xfd2d4 %eax0xfd2ac %esp0xfd290 %ebp0xfd2b8 %eip0x8048407 mycpy: push %ebp mov %esp,%ebp sub $0x28,%esp mov 0x8(%ebp),%eax mov %eax,0x4(%esp) lea -0xc(%ebp),%eax mov %eax,(%esp) call strcpy leave ret main: push %ebp mov %esp,%ebp sub $0x10,%esp movl $0x8048504,(%esp) call mycpy mov $0x8048517,%eax mov %eax,(%esp) call printf mov $0x0,%eax leave ret 0x80483f4 0x80483f5 0x80483f7 0x80483fa 0x80483fd 0x8048401 0x8048404 0x8048407 0x804840c 0x804840d 0x804840e 0x804840f 0x8048414 0x8048417 0x804841e 0x8048423 0x8048428 0x804842b 0x8048430 0x8048435 0x8048436 0xfd2c0 0xfd2bc 0xfd2b8 0xfd290 0xfd2ac
126
Adam Doupé, Principles of Programming Languages 0xfd2e0 0x8048504 0x8048423 0xfd2d0 0x8048504 0xfd2ac 126 0xfd2d4 %eax0xfd2ac %esp0xfd290 %ebp0xfd2b8 %eip0x804840c mycpy: push %ebp mov %esp,%ebp sub $0x28,%esp mov 0x8(%ebp),%eax mov %eax,0x4(%esp) lea -0xc(%ebp),%eax mov %eax,(%esp) call strcpy leave ret main: push %ebp mov %esp,%ebp sub $0x10,%esp movl $0x8048504,(%esp) call mycpy mov $0x8048517,%eax mov %eax,(%esp) call printf mov $0x0,%eax leave ret 0x80483f4 0x80483f5 0x80483f7 0x80483fa 0x80483fd 0x8048401 0x8048404 0x8048407 0x804840c 0x804840d 0x804840e 0x804840f 0x8048414 0x8048417 0x804841e 0x8048423 0x8048428 0x804842b 0x8048430 0x8048435 0x8048436 0xfd2c0 0xfd2bc 0xfd2b8 0xfd290 0xfd2ac
127
Adam Doupé, Principles of Programming Languages 0xfd2e0 0x8048504 0x8048423 0xfd2d0 0x8048504 0xfd2ac 127 0xfd2d4 %eax0xfd2ac %esp0xfd290 %ebp0xfd2b8 %eip0x804840c mycpy: push %ebp mov %esp,%ebp sub $0x28,%esp mov 0x8(%ebp),%eax mov %eax,0x4(%esp) lea -0xc(%ebp),%eax mov %eax,(%esp) call strcpy leave ret main: push %ebp mov %esp,%ebp sub $0x10,%esp movl $0x8048504,(%esp) call mycpy mov $0x8048517,%eax mov %eax,(%esp) call printf mov $0x0,%eax leave ret 0x80483f4 0x80483f5 0x80483f7 0x80483fa 0x80483fd 0x8048401 0x8048404 0x8048407 0x804840c 0x804840d 0x804840e 0x804840f 0x8048414 0x8048417 0x804841e 0x8048423 0x8048428 0x804842b 0x8048430 0x8048435 0x8048436 0xfd2c0 0xfd2bc 0xfd2b8 0xfd290 0xfd2ac 0x8048504: "asu cse 340 fall 2015 rocks!"
128
Adam Doupé, Principles of Programming Languages 0xfd2e0 0x8048504 0x8048423 0xfd2d0 asu (0x20757361) 0x8048504 0xfd2ac 128 0xfd2d4 %eax0xfd2ac %esp0xfd290 %ebp0xfd2b8 %eip0x804840c mycpy: push %ebp mov %esp,%ebp sub $0x28,%esp mov 0x8(%ebp),%eax mov %eax,0x4(%esp) lea -0xc(%ebp),%eax mov %eax,(%esp) call strcpy leave ret main: push %ebp mov %esp,%ebp sub $0x10,%esp movl $0x8048504,(%esp) call mycpy mov $0x8048517,%eax mov %eax,(%esp) call printf mov $0x0,%eax leave ret 0x80483f4 0x80483f5 0x80483f7 0x80483fa 0x80483fd 0x8048401 0x8048404 0x8048407 0x804840c 0x804840d 0x804840e 0x804840f 0x8048414 0x8048417 0x804841e 0x8048423 0x8048428 0x804842b 0x8048430 0x8048435 0x8048436 0xfd2c0 0xfd2bc 0xfd2b8 0xfd290 0xfd2ac 0x8048504: "asu cse 340 fall 2015 rocks!"
129
Adam Doupé, Principles of Programming Languages 0xfd2e0 0x8048504 0x8048423 0xfd2d0 cse (0x20657363) asu (0x20757361) 0x8048504 0xfd2ac 129 0xfd2d4 %eax0xfd2ac %esp0xfd290 %ebp0xfd2b8 %eip0x804840c mycpy: push %ebp mov %esp,%ebp sub $0x28,%esp mov 0x8(%ebp),%eax mov %eax,0x4(%esp) lea -0xc(%ebp),%eax mov %eax,(%esp) call strcpy leave ret main: push %ebp mov %esp,%ebp sub $0x10,%esp movl $0x8048504,(%esp) call mycpy mov $0x8048517,%eax mov %eax,(%esp) call printf mov $0x0,%eax leave ret 0x80483f4 0x80483f5 0x80483f7 0x80483fa 0x80483fd 0x8048401 0x8048404 0x8048407 0x804840c 0x804840d 0x804840e 0x804840f 0x8048414 0x8048417 0x804841e 0x8048423 0x8048428 0x804842b 0x8048430 0x8048435 0x8048436 0xfd2c0 0xfd2bc 0xfd2b8 0xfd290 0xfd2ac 0x8048504: "asu cse 340 fall 2015 rocks!"
130
Adam Doupé, Principles of Programming Languages 0xfd2e0 0x8048504 0x8048423 0xfd2d0 340 (0x20303433) cse (0x20657363) asu (0x20757361) 0x8048504 0xfd2ac 130 0xfd2d4 %eax0xfd2ac %esp0xfd290 %ebp0xfd2b8 %eip0x804840c mycpy: push %ebp mov %esp,%ebp sub $0x28,%esp mov 0x8(%ebp),%eax mov %eax,0x4(%esp) lea -0xc(%ebp),%eax mov %eax,(%esp) call strcpy leave ret main: push %ebp mov %esp,%ebp sub $0x10,%esp movl $0x8048504,(%esp) call mycpy mov $0x8048517,%eax mov %eax,(%esp) call printf mov $0x0,%eax leave ret 0x80483f4 0x80483f5 0x80483f7 0x80483fa 0x80483fd 0x8048401 0x8048404 0x8048407 0x804840c 0x804840d 0x804840e 0x804840f 0x8048414 0x8048417 0x804841e 0x8048423 0x8048428 0x804842b 0x8048430 0x8048435 0x8048436 0xfd2c0 0xfd2bc 0xfd2b8 0xfd290 0xfd2ac 0x8048504: "asu cse 340 fall 2015 rocks!"
131
Adam Doupé, Principles of Programming Languages 0xfd2e0 0x8048504 0x8048423 fall (0x6c6c6166) 340 (0x20303433) cse (0x20657363) asu (0x20757361) 0x8048504 0xfd2ac 131 0xfd2d4 %eax0xfd2ac %esp0xfd290 %ebp0xfd2b8 %eip0x804840c mycpy: push %ebp mov %esp,%ebp sub $0x28,%esp mov 0x8(%ebp),%eax mov %eax,0x4(%esp) lea -0xc(%ebp),%eax mov %eax,(%esp) call strcpy leave ret main: push %ebp mov %esp,%ebp sub $0x10,%esp movl $0x8048504,(%esp) call mycpy mov $0x8048517,%eax mov %eax,(%esp) call printf mov $0x0,%eax leave ret 0x80483f4 0x80483f5 0x80483f7 0x80483fa 0x80483fd 0x8048401 0x8048404 0x8048407 0x804840c 0x804840d 0x804840e 0x804840f 0x8048414 0x8048417 0x804841e 0x8048423 0x8048428 0x804842b 0x8048430 0x8048435 0x8048436 0xfd2c0 0xfd2bc 0xfd2b8 0xfd290 0xfd2ac 0x8048504: "asu cse 340 fall 2015 rocks!"
132
Adam Doupé, Principles of Programming Languages 0xfd2e0 0x8048504 201 (0x31303220) fall (0x6c6c6166) 340 (0x20303433) cse (0x20657363) asu (0x20757361) 0x8048504 0xfd2ac 132 0xfd2d4 %eax0xfd2ac %esp0xfd290 %ebp0xfd2b8 %eip0x804840c mycpy: push %ebp mov %esp,%ebp sub $0x28,%esp mov 0x8(%ebp),%eax mov %eax,0x4(%esp) lea -0xc(%ebp),%eax mov %eax,(%esp) call strcpy leave ret main: push %ebp mov %esp,%ebp sub $0x10,%esp movl $0x8048504,(%esp) call mycpy mov $0x8048517,%eax mov %eax,(%esp) call printf mov $0x0,%eax leave ret 0x80483f4 0x80483f5 0x80483f7 0x80483fa 0x80483fd 0x8048401 0x8048404 0x8048407 0x804840c 0x804840d 0x804840e 0x804840f 0x8048414 0x8048417 0x804841e 0x8048423 0x8048428 0x804842b 0x8048430 0x8048435 0x8048436 0xfd2c0 0xfd2bc 0xfd2b8 0xfd290 0xfd2ac 0x8048504: "asu cse 340 fall 2015 rocks!"
133
Adam Doupé, Principles of Programming Languages 0xfd2e0 5 ro (0x6f722035) 201 (0x31303220) fall (0x6c6c6166) 340 (0x20303433) cse (0x20657363) asu (0x20757361) 0x8048504 0xfd2ac 133 0xfd2d4 %eax0xfd2ac %esp0xfd290 %ebp0xfd2b8 %eip0x804840c mycpy: push %ebp mov %esp,%ebp sub $0x28,%esp mov 0x8(%ebp),%eax mov %eax,0x4(%esp) lea -0xc(%ebp),%eax mov %eax,(%esp) call strcpy leave ret main: push %ebp mov %esp,%ebp sub $0x10,%esp movl $0x8048504,(%esp) call mycpy mov $0x8048517,%eax mov %eax,(%esp) call printf mov $0x0,%eax leave ret 0x80483f4 0x80483f5 0x80483f7 0x80483fa 0x80483fd 0x8048401 0x8048404 0x8048407 0x804840c 0x804840d 0x804840e 0x804840f 0x8048414 0x8048417 0x804841e 0x8048423 0x8048428 0x804842b 0x8048430 0x8048435 0x8048436 0xfd2c0 0xfd2bc 0xfd2b8 0xfd290 0xfd2ac 0x8048504: "asu cse 340 fall 2015 rocks!"
134
Adam Doupé, Principles of Programming Languages 0xfd2e0 cks! (0x21736b63) 5 ro (0x6f722035) 201 (0x31303220) fall (0x6c6c6166) 340 (0x20303433) cse (0x20657363) asu (0x20757361) 0x8048504 0xfd2ac 134 0xfd2d4 %eax0xfd2ac %esp0xfd290 %ebp0xfd2b8 %eip0x804840c mycpy: push %ebp mov %esp,%ebp sub $0x28,%esp mov 0x8(%ebp),%eax mov %eax,0x4(%esp) lea -0xc(%ebp),%eax mov %eax,(%esp) call strcpy leave ret main: push %ebp mov %esp,%ebp sub $0x10,%esp movl $0x8048504,(%esp) call mycpy mov $0x8048517,%eax mov %eax,(%esp) call printf mov $0x0,%eax leave ret 0x80483f4 0x80483f5 0x80483f7 0x80483fa 0x80483fd 0x8048401 0x8048404 0x8048407 0x804840c 0x804840d 0x804840e 0x804840f 0x8048414 0x8048417 0x804841e 0x8048423 0x8048428 0x804842b 0x8048430 0x8048435 0x8048436 0xfd2c0 0xfd2bc 0xfd2b8 0xfd290 0xfd2ac 0x8048504: "asu cse 340 fall 2015 rocks!"
135
Adam Doupé, Principles of Programming Languages 0xfd2e0 cks! (0x21736b63) 5 ro (0x6f722035) 201 (0x31303220) fall (0x6c6c6166) 340 (0x20303433) cse (0x20657363) asu (0x20757361) 0x8048504 0xfd2ac 135 0xfd2d4 %eax0xfd2ac %esp0xfd2b8 %ebp0xfd2b8 %eip0x804840c mycpy: push %ebp mov %esp,%ebp sub $0x28,%esp mov 0x8(%ebp),%eax mov %eax,0x4(%esp) lea -0xc(%ebp),%eax mov %eax,(%esp) call strcpy leave ret main: push %ebp mov %esp,%ebp sub $0x10,%esp movl $0x8048504,(%esp) call mycpy mov $0x8048517,%eax mov %eax,(%esp) call printf mov $0x0,%eax leave ret 0x80483f4 0x80483f5 0x80483f7 0x80483fa 0x80483fd 0x8048401 0x8048404 0x8048407 0x804840c 0x804840d 0x804840e 0x804840f 0x8048414 0x8048417 0x804841e 0x8048423 0x8048428 0x804842b 0x8048430 0x8048435 0x8048436 0xfd2c0 0xfd2bc 0xfd2b8 0xfd290 0xfd2ac 0x8048504: "asu cse 340 fall 2015 rocks!"
136
Adam Doupé, Principles of Programming Languages 0xfd2e0 cks! (0x21736b63) 5 ro (0x6f722035) 201 (0x31303220) fall (0x6c6c6166) 340 (0x20303433) cse (0x20657363) asu (0x20757361) 0x8048504 0xfd2ac 136 0xfd2d4 %eax0xfd2ac %esp0xfd2bc %ebp0x6c6c6166 %eip0x804840c mycpy: push %ebp mov %esp,%ebp sub $0x28,%esp mov 0x8(%ebp),%eax mov %eax,0x4(%esp) lea -0xc(%ebp),%eax mov %eax,(%esp) call strcpy leave ret main: push %ebp mov %esp,%ebp sub $0x10,%esp movl $0x8048504,(%esp) call mycpy mov $0x8048517,%eax mov %eax,(%esp) call printf mov $0x0,%eax leave ret 0x80483f4 0x80483f5 0x80483f7 0x80483fa 0x80483fd 0x8048401 0x8048404 0x8048407 0x804840c 0x804840d 0x804840e 0x804840f 0x8048414 0x8048417 0x804841e 0x8048423 0x8048428 0x804842b 0x8048430 0x8048435 0x8048436 0xfd2c0 0xfd2bc 0xfd2b8 0xfd290 0xfd2ac 0x8048504: "asu cse 340 fall 2015 rocks!"
137
Adam Doupé, Principles of Programming Languages 0xfd2e0 cks! (0x21736b63) 5 ro (0x6f722035) 201 (0x31303220) fall (0x6c6c6166) 340 (0x20303433) cse (0x20657363) asu (0x20757361) 0x8048504 0xfd2ac 137 0xfd2d4 %eax0xfd2ac %esp0xfd2bc %ebp0x6c6c6166 %eip0x804840d mycpy: push %ebp mov %esp,%ebp sub $0x28,%esp mov 0x8(%ebp),%eax mov %eax,0x4(%esp) lea -0xc(%ebp),%eax mov %eax,(%esp) call strcpy leave ret main: push %ebp mov %esp,%ebp sub $0x10,%esp movl $0x8048504,(%esp) call mycpy mov $0x8048517,%eax mov %eax,(%esp) call printf mov $0x0,%eax leave ret 0x80483f4 0x80483f5 0x80483f7 0x80483fa 0x80483fd 0x8048401 0x8048404 0x8048407 0x804840c 0x804840d 0x804840e 0x804840f 0x8048414 0x8048417 0x804841e 0x8048423 0x8048428 0x804842b 0x8048430 0x8048435 0x8048436 0xfd2c0 0xfd2bc 0xfd2b8 0xfd290 0xfd2ac 0x8048504: "asu cse 340 fall 2015 rocks!"
138
Adam Doupé, Principles of Programming Languages 0xfd2e0 cks! (0x21736b63) 5 ro (0x6f722035) 201 (0x31303220) fall (0x6c6c6166) 340 (0x20303433) cse (0x20657363) asu (0x20757361) 0x8048504 0xfd2ac 138 0xfd2d4 %eax0xfd2ac %esp0xfd2c0 %ebp0x6c6c6166 %eip0x31303220 mycpy: push %ebp mov %esp,%ebp sub $0x28,%esp mov 0x8(%ebp),%eax mov %eax,0x4(%esp) lea -0xc(%ebp),%eax mov %eax,(%esp) call strcpy leave ret main: push %ebp mov %esp,%ebp sub $0x10,%esp movl $0x8048504,(%esp) call mycpy mov $0x8048517,%eax mov %eax,(%esp) call printf mov $0x0,%eax leave ret 0x80483f4 0x80483f5 0x80483f7 0x80483fa 0x80483fd 0x8048401 0x8048404 0x8048407 0x804840c 0x804840d 0x804840e 0x804840f 0x8048414 0x8048417 0x804841e 0x8048423 0x8048428 0x804842b 0x8048430 0x8048435 0x8048436 0xfd2c0 0xfd2bc 0xfd2b8 0xfd290 0xfd2ac 0x8048504: "asu cse 340 fall 2015 rocks!"
139
Adam Doupé, Principles of Programming Languages 0xfd2e0 cks! (0x21736b63) 5 ro (0x6f722035) 201 (0x31303220) fall (0x6c6c6166) 340 (0x20303433) cse (0x20657363) asu (0x20757361) 0x8048504 0xfd2ac 139 0xfd2d4 %eax0xfd2ac %esp0xfd2c0 %ebp0x6c6c6166 %eip0x31303220 mycpy: push %ebp mov %esp,%ebp sub $0x28,%esp mov 0x8(%ebp),%eax mov %eax,0x4(%esp) lea -0xc(%ebp),%eax mov %eax,(%esp) call strcpy leave ret main: push %ebp mov %esp,%ebp sub $0x10,%esp movl $0x8048504,(%esp) call mycpy mov $0x8048517,%eax mov %eax,(%esp) call printf mov $0x0,%eax leave ret 0x80483f4 0x80483f5 0x80483f7 0x80483fa 0x80483fd 0x8048401 0x8048404 0x8048407 0x804840c 0x804840d 0x804840e 0x804840f 0x8048414 0x8048417 0x804841e 0x8048423 0x8048428 0x804842b 0x8048430 0x8048435 0x8048436 0xfd2c0 0xfd2bc 0xfd2b8 0xfd290 0xfd2ac 0x8048504: "asu cse 340 fall 2015 rocks!"
140
Adam Doupé, Principles of Programming Languages #include void mycpy(char* str) { char foo[4]; strcpy(foo, str); } int main() { callee("asu cse 340 fall 2015 rocks!"); printf("After"); return 0; } 140 [adamd@ragnuk examples]$ gcc - Wall -m32 buffer_overflow.c [adamd@ragnuk examples]$./a.out Segmentation fault (core dumped) [adamd@ragnuk examples]$ gdb./a.out (gdb) r Starting program: a.out Program received signal SIGSEGV, Segmentation fault.0x31303220 in ?? () (gdb) info registers eax 0xffffd1fc -11780 ecx 0x0 0 edx 0x8048521 134513953 ebx 0x908ff4 9474036 esp 0xffffd210 0xffffd210 ebp 0x6c6c6166 0x6c6c6166 esi 0x0 0 edi 0x0 0 eip 0x31303220 0x31303220e...
141
Adam Doupé, Principles of Programming Languages Buffer Overflow Classic security vulnerability is when an attacker can overwrite the saved EIP value on the stack –The attacker's goal is to change a saved EIP value to point to attacker's data –Where the program will start executing the attacker's data as code One of the most common vulnerabilities in C and C++ programs Why? 141
142
Adam Doupé, Principles of Programming Languages Local Functions From what we have seen so far, variables are either global or local What if we want a language that allows defining local functions –Functions that are only valid in the containing scope 142
143
Adam Doupé, Principles of Programming Languages #include void foo() { int x; void bar() { void baz() { x = x + 1; if (x < 10) { bar(); } } baz(); } x = 0; bar(); printf("%d\n", x); } 143 [adamd@ragnuk]$ gcc –Wall local_functions.c [adamd@ragnuk]$./a.out 10
144
Adam Doupé, Principles of Programming Languages Local Functions Can the previously discussed cdecl calling convention support support local functions? 144
145
Adam Doupé, Principles of Programming Languages #include void foo() { int x; void bar() { void baz() { x = x + 1; if (x < 10) { bar(); } baz(); } x = 0; bar(); printf("%d\n", x); } 145 foo
146
Adam Doupé, Principles of Programming Languages #include void foo() { int x; void bar() { void baz() { x = x + 1; if (x < 10) { bar(); } baz(); } x = 0; bar(); printf("%d\n", x); } 146 foo bar
147
Adam Doupé, Principles of Programming Languages #include void foo() { int x; void bar() { void baz() { x = x + 1; if (x < 10) { bar(); } baz(); } x = 0; bar(); printf("%d\n", x); } 147 foo bar
148
Adam Doupé, Principles of Programming Languages #include void foo() { int x; void bar() { void baz() { x = x + 1; if (x < 10) { bar(); } baz(); } x = 0; bar(); printf("%d\n", x); } 148 foo bar baz
149
Adam Doupé, Principles of Programming Languages #include void foo() { int x; void bar() { void baz() { x = x + 1; if (x < 10) { bar(); } baz(); } x = 0; bar(); printf("%d\n", x); } 149 foo bar baz
150
Adam Doupé, Principles of Programming Languages #include void foo() { int x; void bar() { void baz() { x = x + 1; if (x < 10) { bar(); } baz(); } x = 0; bar(); printf("%d\n", x); } 150 foo bar baz bar
151
Adam Doupé, Principles of Programming Languages #include void foo() { int x; void bar() { void baz() { x = x + 1; if (x < 10) { bar(); } baz(); } x = 0; bar(); printf("%d\n", x); } 151 foo bar baz bar baz
152
Adam Doupé, Principles of Programming Languages #include void foo() { int x; void bar() { void baz() { x = x + 1; if (x < 10) { bar(); } baz(); } x = 0; bar(); printf("%d\n", x); } 152 foo bar baz bar baz
153
Adam Doupé, Principles of Programming Languages Access Link Saved base pointer (EBP) save the caller's base pointer We want the base pointer of our lexical parent, not our caller's parent Thus, we need to add another element to our calling convention –This is called the "access link" Therefore, a function can follow the access links until the last lexical scope is found 153
154
Adam Doupé, Principles of Programming Languages #include void foo() { int x; void bar() { void baz() { x = x + 1; if (x < 10) { bar(); } baz(); } x = 0; bar(); printf("%d\n", x); } 154 foo bar baz bar baz
155
Adam Doupé, Principles of Programming Languages #include void foo() { int x; void bar() { void baz() { x = x + 1; if (x < 10) { bar(); } baz(); } x = 0; bar(); printf("%d\n", x); } 155 foo bar baz bar baz bar baz bar baz
156
Adam Doupé, Principles of Programming Languages Type of Memory Allocation Global Allocation Stack Allocation Heap Allocation 156
157
Adam Doupé, Principles of Programming Languages Heap Allocation Programmer must manually ask for memory allocation Programmer must also explicitly release the memory 157
158
Adam Doupé, Principles of Programming Languages C Heap Allocation Defined in libc (stdlib.h) –malloc –calloc –realloc –free Many possible implementations –In fact, you can write your own! 158
159
Adam Doupé, Principles of Programming Languages #include int main(int argc, char** argv) { void* test; int i; int size = atoi(argv[1]); for (i = 0; i < 10; i++) { test = malloc(size); printf("%p\n", test); } return 0; } 159 [adamd@ragnuk]$ gcc –Wall –m32 malloc_test.c [adamd@ragnuk]$./a.out 4 0x804a008 0x804a018 0x804a028 0x804a038 0x804a048 0x804a058 0x804a068 0x804a078 0x804a088 0x804a098
160
Adam Doupé, Principles of Programming Languages #include int main(int argc, char** argv) { void* test; int i; int size = atoi(argv[1]); for (i = 0; i < 10; i++) { test = malloc(size); printf("%p\n", test); } return 0; } 160 [adamd@ragnuk]$ gcc –Wall –m32 malloc_test.c [adamd@ragnuk]$./a.out 8 0x804a008 0x804a018 0x804a028 0x804a038 0x804a048 0x804a058 0x804a068 0x804a078 0x804a088 0x804a098
161
Adam Doupé, Principles of Programming Languages #include int main(int argc, char** argv) { void* test; int i; int size = atoi(argv[1]); for (i = 0; i < 10; i++) { test = malloc(size); printf("%p\n", test); } return 0; } 161 [adamd@ragnuk]$ gcc –Wall –m32 malloc_test.c [adamd@ragnuk]$./a.out 24 0x804a008 0x804a028 0x804a048 0x804a068 0x804a088 0x804a0a8 0x804a0c8 0x804a0e8 0x804a108 0x804a128
162
Adam Doupé, Principles of Programming Languages #include int main(int argc, char** argv) { void* test; int i; int size = atoi(argv[1]); for (i = 0; i < 10; i++) { test = malloc(size); printf("%p\n", test); } return 0; } 162 [adamd@ragnuk]$ gcc –Wall –m32 malloc_test.c [adamd@ragnuk]$./a.out 4096 0x804a008 0x804b010 0x804c018 0x804d020 0x804e028 0x804f030 0x8050038 0x8051040 0x8052048 0x8053050
163
Adam Doupé, Principles of Programming Languages #include int main(int argc, char** argv) { void* test; int i; int size = atoi(argv[1]); for (i = 0; i < 10; i++) { test = malloc(size); printf("%p\n", test); } return 0; } 163 [adamd@ragnuk]$ gcc –Wall –m32 malloc_test.c [adamd@ragnuk]$./a.out 536870911 0xd7fec008 0xb7feb008 0x97fea008 0x77fe9008 0x57fe8008 0x37fe7008 0x17fe6008 (nil)
164
Adam Doupé, Principles of Programming Languages 164 0xFFFFFFFF 0x00000000 Stack Heap
165
Adam Doupé, Principles of Programming Languages Heap Allocation sbrk is Linux system call to increase the size of the heap –Defined in unistd.h – void* sbrk(intptr_t increment) Thus, malloc does not allocate new heap directly, but instead calls sbrk to ask the OS to increase heap allocation 165
166
Adam Doupé, Principles of Programming Languages #include int main(int argc, char** argv) { void* test; void* cur_break; int i; int size = atoi(argv[1]); for (i = 0; i < 10; i++) { test = malloc(size); cur_break = sbrk(0); printf("%p %p\n", test, cur_break); } return 0; } 166 [adamd@ragnuk]$ gcc –Wall –m32 sbrk_test.c [adamd@ragnuk]$./a.out 4 0x804a008 0x806b000 0x804a018 0x806b000 0x804a028 0x806b000 0x804a038 0x806b000 0x804a048 0x806b000 0x804a058 0x806b000 0x804a068 0x806b000 0x804a078 0x806b000 0x804a088 0x806b000 0x804a098 0x806b000
167
Adam Doupé, Principles of Programming Languages #include int main(int argc, char** argv) { void* test; void* cur_break; int i; int size = atoi(argv[1]); for (i = 0; i < 10; i++) { test = malloc(size); cur_break = sbrk(0); printf("%p %p\n", test, cur_break); } return 0; } 167 [adamd@ragnuk]$ gcc –Wall –m32 sbrk_test.c [adamd@ragnuk]$./a.out 1024 0x804a008 0x806b000 0x804a410 0x806b000 0x804a818 0x806b000 0x804ac20 0x806b000 0x804b028 0x806b000 0x804b430 0x806b000 0x804b838 0x806b000 0x804bc40 0x806b000 0x804c048 0x806b000 0x804c450 0x806b000
168
Adam Doupé, Principles of Programming Languages #include int main(int argc, char** argv) { void* test; void* cur_break; int i; int size = atoi(argv[1]); for (i = 0; i < 10; i++) { test = malloc(size); cur_break = sbrk(0); printf("%p %p\n", test, cur_break); } return 0; } 168 [adamd@ragnuk]$ gcc –Wall –m32 sbrk_test.c [adamd@ragnuk]$./a.out 4096 0x804a008 0x806c000 0x804b010 0x806c000 0x804c018 0x806c000 0x804d020 0x806c000 0x804e028 0x806c000 0x804f030 0x806c000 0x8050038 0x806c000 0x8051040 0x806c000 0x8052048 0x806c000 0x8053050 0x806c000
169
Adam Doupé, Principles of Programming Languages #include int main(int argc, char** argv) { void* test; void* cur_break; int i; int size = atoi(argv[1]); for (i = 0; i < 10; i++) { test = malloc(size); cur_break = sbrk(0); printf("%p %p\n", test, cur_break); } return 0; } 169 [adamd@ragnuk]$ gcc –Wall –m32 sbrk_test.c [adamd@ragnuk]$./a.out 65536 0x804a008 0x807b000 0x805a010 0x807b000 0x806a018 0x807b000 0x807a020 0x80ab000 0x808a028 0x80ab000 0x809a030 0x80ab000 0x80aa038 0x80db000 0x80ba040 0x80db000 0x80ca048 0x80db000 0x80da050 0x810b000
170
Adam Doupé, Principles of Programming Languages Heap Allocation So malloc is calling sbrk to request more heap memory from the OS How is the memory deallocated when we call free ? 170
171
Adam Doupé, Principles of Programming Languages #include int main(int argc, char** argv) { void* test; void* cur_break; int i; int size = atoi(argv[1]); for (i = 0; i < 10; i++) { test = malloc(size); cur_break = sbrk(0); printf("%p %p\n", test, cur_break); free(test); } return 0; } 171 [adamd@ragnuk]$ gcc –Wall –m32 free_test.c [adamd@ragnuk]$./a.out 4 0x804a008 0x806b000
172
Adam Doupé, Principles of Programming Languages #include int main(int argc, char** argv) { void* test; void* cur_break; int i; int size = atoi(argv[1]); for (i = 0; i < 10; i++) { test = malloc(size); cur_break = sbrk(0); printf("%p %p\n", test, cur_break); free(test); } return 0; } 172 [adamd@ragnuk]$ gcc –Wall –m32 free_test.c [adamd@ragnuk]$./a.out 1024 0x804a008 0x806b000
173
Adam Doupé, Principles of Programming Languages #include int main(int argc, char** argv) { void* test; void* cur_break; int i; int size = atoi(argv[1]); for (i = 0; i < 10; i++) { test = malloc(size); cur_break = sbrk(0); printf("%p %p\n", test, cur_break); if (i % 2 == 0) free(test); } return 0; } 173 [adamd@ragnuk]$ gcc –Wall –m32 free_test_2.c [adamd@ragnuk]$./a.out 4 0x804a008 0x806b000 0x804a018 0x806b000 0x804a028 0x806b000 0x804a038 0x806b000 0x804a048 0x806b000
174
Adam Doupé, Principles of Programming Languages free How would you implement malloc and free ? void* malloc(size_t size) void free(void* ptr) malloc must call sbrk to increase heap to size –return the pointer that sbrk returns free –set sbrk to negative allocated size 174
175
Adam Doupé, Principles of Programming Languages Implementation Reserve more memory than requested Store the malloc'd size in a fixed offset from the pointer to the new memory Then, when someone calls free, access the size from the fixed offset of that pointer 175
176
Adam Doupé, Principles of Programming Languages struct malloc_chunk { size_t chunk_size; void* buf; }; void* malloc (size_t size) { … struct malloc_chunk* new_mem = sbrk(size + sizeof(struct malloc_chunk); new_mem->chunk_size = size; return (void*)((char*)new_mem + sizeof(size_t)); } void free (void* ptr) { struct malloc_chunk* mem = (struct malloc_chunk*)((char*)ptr – sizeof(size_t)); size_t size_to_free = mem->chunk_size; … } 176
177
Adam Doupé, Principles of Programming Languages 177 0xFFFFFFFF 0x00000000 Stack Heap
178
Adam Doupé, Principles of Programming Languages 178 0xFFFFFFFF 0x00000000 Stack Heap
179
Adam Doupé, Principles of Programming Languages 179 0xFFFFFFFF 0x00000000 Stack Heap
180
Adam Doupé, Principles of Programming Languages 180 0xFFFFFFFF 0x00000000 sbrk(size)
181
Adam Doupé, Principles of Programming Languages 181 0xFFFFFFFF 0x00000000
182
Adam Doupé, Principles of Programming Languages 182 0xFFFFFFFF 0x00000000
183
Adam Doupé, Principles of Programming Languages 183 0xFFFFFFFF 0x00000000
184
Adam Doupé, Principles of Programming Languages 184 0xFFFFFFFF 0x00000000
185
Adam Doupé, Principles of Programming Languages 185 0xFFFFFFFF 0x00000000
186
Adam Doupé, Principles of Programming Languages 186 0xFFFFFFFF 0x00000000
187
Adam Doupé, Principles of Programming Languages 187 0xFFFFFFFF 0x00000000
188
Adam Doupé, Principles of Programming Languages Modern malloc Many applications need heap allocation, thus malloc performance very important Different heap workloads –Many small and frequent allocations –Few large allocations –Combination of both Many things affect performance –Finding free memory –Heap fragmentation –Allocation overhead 188
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.