gcc - C++ compiler function call -



gcc - C++ compiler function call -

why compiler set much commands before function phone call (look @ link below)? understand, should pass function parameters before call.

struct a{ int c = 5; void test(unsigned int a){ a++; c++; } }; struct c{ int k =2; a; }; struct d{ int k =2; c c; }; struct b{ int k =2; d d; }; void test(unsigned int a){ a++; } b *b = new b(); *ae = new a(); int main() { int = 1; ai; b bi; c ci; // 2 operations (why not pop/push ?) // movl -36(%rbp), %eax // movl %eax, %edi // phone call test(unsigned int) test(a); // 4 operations (why 4? pass else?) // movl -36(%rbp), %edx // leaq -48(%rbp), %rax // movl %edx, %esi // movq %rax, %rdi // phone call a::test(unsigned int) ai.test(a); ae->test(a); // 5 operations before phone call (what hell going here?, why "addq" ?) // movl -36(%rbp), %eax // leaq -32(%rbp), %rdx // addq $4, %rdx // movl %eax, %esi // movq %rdx, %rdi // phone call a::test(unsigned int) ci.a.test(a); bi.d.c.a.test(a); b->d.c.a.test(a); // no matter how long chain - took 5 operations }

http://goo.gl/smfsa6

why when phone call class member, took 4 additional commands prepare call? load object address register, well?

and lastly case 5 ops, beyond me...

p.s. in days of youth, usually, set function params stack (push), read them (pop). what, pass parameters through registers?

it's normal. in assembly intruction doing 1 thing. illustration in lastly case:

movl -36(%rbp), %eax ; move %eax leaq -32(%rbp), %rdx ; move & ci %rdx addq $4, %rdx ; set %rdx ci->a = ci + offset of movl %eax, %esi ; move %eax %esi (second parameter) movq %rdx, %rdi ; move ci->a %rdx %rdi (first parameter) phone call a::test(unsigned int) ; phone call a::test

in 64 bit linux systems function parameters no longer transferred on stack, first 6 integer parameters transferred in %rdi, %rsi, %rdx, %rcx, %r8, %r9 registers. floating point values utilize %xmm0 - %xmm7 registers, , others transferred on stack.

the local variables of course of study located on stack , accessed through %rbp

c++ gcc asmx disassembling

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -