Posts

Understanding Function Call Stack

Understanding Function Call Stack This writeup shows stack operations and behavior with a simple C Program, Assembly code and a dump of stack memory. Contents : Code Analysis of Stack Operations Analysis of Stack memory dump Full C Code Full Objdump C Code Assembly Code int main() { int a = 1; int b = 2; int c = 3; int d = 4; int e = 5; int f = 6; int g = 7; int h = 8; int ret = 0; ret = fun1(a, b, c, d, e, f, g, h); printf("output is %d", ret); } 0000000000400868 : 400868: push %rbp 400869: mov %rsp,%rbp 40086c: sub $0x30,%rsp 400870: movl $0x1,-0x4(%rbp) 400877: movl $0x2,-0x8(%rbp) 40087e: movl $0x3,-0xc(%rbp) 400885: movl $0x4,-0x10(%rbp) 40088c: movl $0x5,-0x14(%rbp) 400893: movl $0x6,-0x18(%rbp) 40089a: movl $0x7,-0x1c(%rbp) 4008a1: movl $0x8,-0x20(%rbp) 4008a8: movl $0x0,-0x24(%rbp) 4008af: mov -0x18(%rbp),%r9d
Recent posts