changeset 614:b74d7a249642

disas example for explicit cdecl declared thiscall
author Tassilo Philipp
date Sat, 01 Oct 2022 16:04:40 +0200
parents 3c3e321875f7
children 516d72e98253
files doc/disas_examples/x86.cdecl.disas doc/disas_examples/x86.fastcall_borland.disas
diffstat 2 files changed, 60 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/doc/disas_examples/x86.cdecl.disas	Sat Oct 01 16:03:25 2022 +0200
+++ b/doc/disas_examples/x86.cdecl.disas	Sat Oct 01 16:04:40 2022 +0200
@@ -790,5 +790,59 @@
 
 
 
+; ---------- cdecl-declared (explicit) C++ thiscall w/ msvc ---------->
+;
+; class C {
+; public:
+;     float __cdecl m(int i) const { return float(i + 123); }
+; };
+;
+; extern "C" {
+;     float f()
+;     {
+;         C c;
+;         return c.m(27);
+;     }
+; }
+
+
+
+; output from godbolt compiler explorer w/ msvc 19.0
+
+tv68 = -8
+tv67 = -4
+_i$ = 12
+float C::m(int)const  PROC
+        push    ebp                      ;
+        mov     ebp, esp                 ;
+        sub     esp, 8                   ;
+        mov     eax, DWORD PTR _i$[ebp]  ;
+        add     eax, 123                 ; |
+        mov     DWORD PTR tv67[ebp], eax ; / in arg + 123, pushed onto stack
+        fild    DWORD PTR tv67[ebp]      ; \
+        fstp    DWORD PTR tv68[ebp]      ; | float cast and put return value in fp0
+        fld     DWORD PTR tv68[ebp]      ; |
+        mov     esp, ebp                 ;
+        pop     ebp                      ;
+        ret     0                        ;
+float C::m(int)const  ENDP
+
+_c$ = -1
+_f      PROC                             ;
+        push    ebp                      ;
+        mov     ebp, esp                 ;
+        push    ecx                      ;
+        push    27                       ; arg 1
+        lea     eax, DWORD PTR _c$[ebp]  ; |
+        push    eax                      ; | arg 0 (this ptr)
+        call    float C::m(int)const     ; call C::m()
+        add     esp, 8                   ;
+        mov     esp, ebp                 ;
+        pop     ebp                      ;
+        ret     0                        ;
+_f      ENDP
+
+
+
 ; vim: ft=asm
 
--- a/doc/disas_examples/x86.fastcall_borland.disas	Sat Oct 01 16:03:25 2022 +0200
+++ b/doc/disas_examples/x86.fastcall_borland.disas	Sat Oct 01 16:04:40 2022 +0200
@@ -5,7 +5,7 @@
 ;     __int32 i2;
 ; };
 ; #pragma pack(pop)
-; 
+;
 ; TTest __fastcall DoTest()
 ; {
 ;     TTest t;
@@ -13,13 +13,14 @@
 ;     t.i2 = 2;
 ;     return t;
 ; }
-; 
+;
 ; ...
 ; TTest t = DoTest();
 
+
+
 ; from http://codeverge.com/embarcadero.cppbuilder.cpp/does-fastcall-have-any-bearing-on/1043767
 
-
 DoTest():
   push ebp                     ; |
   mov ebp,esp                  ; | prolog
@@ -37,5 +38,7 @@
   pop ebp                      ; | epilog
   ret                          ; |
 
+
+
 ; vim: ft=asm