diff 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
line wrap: on
line diff
--- a/doc/disas_examples/x86.cdecl.disas	Mon Mar 21 18:11:38 2022 +0100
+++ b/doc/disas_examples/x86.cdecl.disas	Wed Mar 23 15:24:31 2022 +0100
@@ -633,5 +633,87 @@
 
 
 
+; ---------- C++ trivial and non-trivial aggrs passed to C funcs ---------->
+;
+; struct Trivial { int a; };
+; struct NonTrivial { int a; NonTrivial() : a(0) {} NonTrivial(const NonTrivial& rhs) : a(rhs.a) { } };
+;
+; extern "C" {
+; 
+;     void f1(struct Trivial s)    { }
+;     void f2(struct NonTrivial s) { }
+;
+;     void f()
+;     {
+;         struct Trivial t;
+;         struct NonTrivial n;
+;         int a=1;
+;         a += 123;
+;         f1(t);
+;         a -= 123;
+;         f2(n);
+;         a -= 12;
+;     }
+; }
+
+
+
+; output from openbsd-4.0-x86 w/ gcc 3.3.5 (propolice)
+
+1c0005a0 <f1>:
+1c0005a0:       55                      push   %ebp
+1c0005a1:       89 e5                   mov    %esp,%ebp
+1c0005a3:       c9                      leave
+1c0005a4:       c3                      ret
+1c0005a5:       90                      nop
+
+1c0005a6 <f2>:
+1c0005a6:       55                      push   %ebp
+1c0005a7:       89 e5                   mov    %esp,%ebp
+1c0005a9:       c9                      leave
+1c0005aa:       c3                      ret
+1c0005ab:       90                      nop
+
+1c0005ac <f>:
+1c0005ac:       55                      push   %ebp                              ;
+1c0005ad:       89 e5                   mov    %esp,%ebp                         ;
+1c0005af:       83 ec 48                sub    $0x48,%esp                        ;
+1c0005b2:       83 ec 0c                sub    $0xc,%esp                         ;
+1c0005b5:       8d 45 d8                lea    0xffffffd8(%ebp),%eax             ;
+1c0005b8:       50                      push   %eax                              ;
+1c0005b9:       e8 8e 00 00 00          call   1c00064c <_ZN10NonTrivialC1Ev>    ; NonTrivial::NonTrivial() / ctor
+1c0005be:       83 c4 10                add    $0x10,%esp                        ;
+1c0005c1:       c7 45 d4 01 00 00 00    movl   $0x1,0xffffffd4(%ebp)             ;
+1c0005c8:       8d 45 d4                lea    0xffffffd4(%ebp),%eax             ;
+1c0005cb:       83 00 7b                addl   $0x7b,(%eax)                      ;
+1c0005ce:       83 ec 0c                sub    $0xc,%esp                         ;
+1c0005d1:       8b 45 f4                mov    0xfffffff4(%ebp),%eax             ;
+1c0005d4:       50                      push   %eax                              ;
+1c0005d5:       e8 c6 ff ff ff          call   1c0005a0 <f1>                     ; call f1(struct Trivial)
+1c0005da:       83 c4 10                add    $0x10,%esp                        ;
+1c0005dd:       8d 45 d4                lea    0xffffffd4(%ebp),%eax             ;
+1c0005e0:       83 28 7b                subl   $0x7b,(%eax)                      ;
+1c0005e3:       83 ec 0c                sub    $0xc,%esp                         ;
+1c0005e6:       83 ec 0c                sub    $0xc,%esp                         ;
+1c0005e9:       8d 45 d8                lea    0xffffffd8(%ebp),%eax             ; |               |
+1c0005ec:       50                      push   %eax                              ; |               / ptr to n
+1c0005ed:       8d 45 b8                lea    0xffffffb8(%ebp),%eax             ; |               \
+1c0005f0:       50                      push   %eax                              ; | copy n        | ptr to dest of copy of n
+1c0005f1:       e8 64 00 00 00          call   1c00065a <_ZN10NonTrivialC1ERKS_> ; |               NonTrivial::NonTrivial(const NonTrivial&) / copy ctor
+1c0005f6:       83 c4 14                add    $0x14,%esp                        ;
+1c0005f9:       8d 45 b8                lea    0xffffffb8(%ebp),%eax             ; |
+1c0005fc:       50                      push   %eax                              ; | f2 arg 0 (ptr to copy of struct NonTrivial), via ptr as non-trivial
+1c0005fd:       e8 a4 ff ff ff          call   1c0005a6 <f2>                     ; call f2(struct NonTrivial)
+1c000602:       83 c4 10                add    $0x10,%esp                        ;
+1c000605:       8d 45 d4                lea    0xffffffd4(%ebp),%eax             ;
+1c000608:       83 28 0c                subl   $0xc,(%eax)                       ;
+1c00060b:       c9                      leave                                    ;
+1c00060c:       c3                      ret                                      ;
+1c00060d:       90                      nop                                      ;
+
+  ; ... snip, removed code of ctor and copy ctor ...
+
+
+
 ; vim: ft=asm