comparison doc/disas_examples/x86.cdecl.disas @ 497:cb19b2fe2422

- more disas examples to check behaviour of passing C++ non-trivial aggregates by value; they all behave the same, calling the copy ctor first, passing a pointer then
author Tassilo Philipp
date Wed, 23 Mar 2022 15:24:31 +0100
parents 4e84d6faed54
children fc614cb865c6
comparison
equal deleted inserted replaced
496:da5232da6270 497:cb19b2fe2422
631 ret 0 ; | 631 ret 0 ; |
632 _main ENDP 632 _main ENDP
633 633
634 634
635 635
636 ; ---------- C++ trivial and non-trivial aggrs passed to C funcs ---------->
637 ;
638 ; struct Trivial { int a; };
639 ; struct NonTrivial { int a; NonTrivial() : a(0) {} NonTrivial(const NonTrivial& rhs) : a(rhs.a) { } };
640 ;
641 ; extern "C" {
642 ;
643 ; void f1(struct Trivial s) { }
644 ; void f2(struct NonTrivial s) { }
645 ;
646 ; void f()
647 ; {
648 ; struct Trivial t;
649 ; struct NonTrivial n;
650 ; int a=1;
651 ; a += 123;
652 ; f1(t);
653 ; a -= 123;
654 ; f2(n);
655 ; a -= 12;
656 ; }
657 ; }
658
659
660
661 ; output from openbsd-4.0-x86 w/ gcc 3.3.5 (propolice)
662
663 1c0005a0 <f1>:
664 1c0005a0: 55 push %ebp
665 1c0005a1: 89 e5 mov %esp,%ebp
666 1c0005a3: c9 leave
667 1c0005a4: c3 ret
668 1c0005a5: 90 nop
669
670 1c0005a6 <f2>:
671 1c0005a6: 55 push %ebp
672 1c0005a7: 89 e5 mov %esp,%ebp
673 1c0005a9: c9 leave
674 1c0005aa: c3 ret
675 1c0005ab: 90 nop
676
677 1c0005ac <f>:
678 1c0005ac: 55 push %ebp ;
679 1c0005ad: 89 e5 mov %esp,%ebp ;
680 1c0005af: 83 ec 48 sub $0x48,%esp ;
681 1c0005b2: 83 ec 0c sub $0xc,%esp ;
682 1c0005b5: 8d 45 d8 lea 0xffffffd8(%ebp),%eax ;
683 1c0005b8: 50 push %eax ;
684 1c0005b9: e8 8e 00 00 00 call 1c00064c <_ZN10NonTrivialC1Ev> ; NonTrivial::NonTrivial() / ctor
685 1c0005be: 83 c4 10 add $0x10,%esp ;
686 1c0005c1: c7 45 d4 01 00 00 00 movl $0x1,0xffffffd4(%ebp) ;
687 1c0005c8: 8d 45 d4 lea 0xffffffd4(%ebp),%eax ;
688 1c0005cb: 83 00 7b addl $0x7b,(%eax) ;
689 1c0005ce: 83 ec 0c sub $0xc,%esp ;
690 1c0005d1: 8b 45 f4 mov 0xfffffff4(%ebp),%eax ;
691 1c0005d4: 50 push %eax ;
692 1c0005d5: e8 c6 ff ff ff call 1c0005a0 <f1> ; call f1(struct Trivial)
693 1c0005da: 83 c4 10 add $0x10,%esp ;
694 1c0005dd: 8d 45 d4 lea 0xffffffd4(%ebp),%eax ;
695 1c0005e0: 83 28 7b subl $0x7b,(%eax) ;
696 1c0005e3: 83 ec 0c sub $0xc,%esp ;
697 1c0005e6: 83 ec 0c sub $0xc,%esp ;
698 1c0005e9: 8d 45 d8 lea 0xffffffd8(%ebp),%eax ; | |
699 1c0005ec: 50 push %eax ; | / ptr to n
700 1c0005ed: 8d 45 b8 lea 0xffffffb8(%ebp),%eax ; | \
701 1c0005f0: 50 push %eax ; | copy n | ptr to dest of copy of n
702 1c0005f1: e8 64 00 00 00 call 1c00065a <_ZN10NonTrivialC1ERKS_> ; | NonTrivial::NonTrivial(const NonTrivial&) / copy ctor
703 1c0005f6: 83 c4 14 add $0x14,%esp ;
704 1c0005f9: 8d 45 b8 lea 0xffffffb8(%ebp),%eax ; |
705 1c0005fc: 50 push %eax ; | f2 arg 0 (ptr to copy of struct NonTrivial), via ptr as non-trivial
706 1c0005fd: e8 a4 ff ff ff call 1c0005a6 <f2> ; call f2(struct NonTrivial)
707 1c000602: 83 c4 10 add $0x10,%esp ;
708 1c000605: 8d 45 d4 lea 0xffffffd4(%ebp),%eax ;
709 1c000608: 83 28 0c subl $0xc,(%eax) ;
710 1c00060b: c9 leave ;
711 1c00060c: c3 ret ;
712 1c00060d: 90 nop ;
713
714 ; ... snip, removed code of ctor and copy ctor ...
715
716
717
636 ; vim: ft=asm 718 ; vim: ft=asm
637 719