comparison doc/disas_examples/x64.win.disas @ 493:75cb8f79d725

- doc and disas examples update about C++ non-trivial aggregates
author Tassilo Philipp
date Mon, 21 Mar 2022 14:46:38 +0100
parents 79b95db3d68f
children fc614cb865c6
comparison
equal deleted inserted replaced
492:29d09d10ecd9 493:75cb8f79d725
421 add rsp, 56 ; | 421 add rsp, 56 ; |
422 ret 0 ; | epilog 422 ret 0 ; | epilog
423 main ENDP 423 main ENDP
424 424
425 425
426
427 ; ---------- C++ trivial and non-trivial aggrs passed to C funcs ---------->
428 ;
429 ; struct Trivial { int a; };
430 ; struct NonTrivial { int a; NonTrivial() : a(0) {} NonTrivial(const NonTrivial& rhs) : a(rhs.a) { } };
431 ;
432 ; extern "C" {
433 ;
434 ; void f1(struct Trivial s) { }
435 ; void f2(struct NonTrivial s) { }
436 ;
437 ; void f()
438 ; {
439 ; struct Trivial t;
440 ; struct NonTrivial n;
441 ; int a=1;
442 ; a += 123;
443 ; f1(t);
444 ; a -= 123;
445 ; f2(n);
446 ; a -= 12;
447 ; }
448 ; }
449
450
451
452 ; output from godbolt compiler explorer w/ msvc 19.0
453
454 ; ... snip, removed code of ctor and copy ctor ...
455
456 f1 PROC
457 mov DWORD PTR [rsp+8], ecx
458 ret 0
459 f1 ENDP
460
461 f2 PROC
462 mov QWORD PTR [rsp+8], rcx
463 ret 0
464 f2 ENDP
465
466 a$ = 32
467 n$ = 36
468 t$ = 40
469 $T1 = 44
470 $T2 = 48
471 f PROC
472 $LN3:
473 sub rsp, 72 ; prolog
474 lea rcx, QWORD PTR n$[rsp] ; \ this ptr (NULL)
475 call NonTrivial::NonTrivial(void) ; | NonTrivial::NonTrivial() / ctor
476 mov DWORD PTR a$[rsp], 1 ; a = 1
477 mov eax, DWORD PTR a$[rsp] ; |
478 add eax, 123 ; | a += 123
479 mov DWORD PTR a$[rsp], eax ; /
480 mov ecx, DWORD PTR t$[rsp] ; f1 arg 0 (struct Trivial), via reg as small struct
481 call f1 ; call f1(struct Trivial)
482 mov eax, DWORD PTR a$[rsp] ; |
483 sub eax, 123 ; | a -= 123
484 mov DWORD PTR a$[rsp], eax ; /
485 lea rax, QWORD PTR $T1[rsp] ; @@@ unsure
486 mov QWORD PTR $T2[rsp], rax ; ... @@@
487 lea rdx, QWORD PTR n$[rsp] ; \ ptr to dest of copy of n
488 mov rcx, QWORD PTR $T2[rsp] ; | copy n ptr to n
489 call NonTrivial::NonTrivial(NonTrivial const &) ; / NonTrivial::NonTrivial(const NonTrivial&) / copy ctor
490 mov rcx, rax ; f2 arg 0 (ptr to copy of struct NonTrivial), via ptr as non-trivial
491 call f2 ; call f2(struct NonTrivial)
492 mov eax, DWORD PTR a$[rsp] ; |
493 sub eax, 12 ; | a -= 12
494 mov DWORD PTR a$[rsp], eax ; /
495 add rsp, 72 ; \
496 ret 0 ; | epilog
497 f ENDP
498
499
500
426 ; vim: ft=asm 501 ; vim: ft=asm
427 502