view doc/disas_examples/x86.thiscall_ms.disas @ 615:516d72e98253

- more thiscall disas examples
author Tassilo Philipp
date Sat, 01 Oct 2022 16:14:00 +0200
parents
children
line wrap: on
line source

; class C {
; public:
;     float 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

_this$ = -12
tv68 = -8
tv67 = -4
_i$ = 8
float C::m(int)const  PROC
        push    ebp                        ;
        mov     ebp, esp                   ;
        sub     esp, 12                    ;
        mov     DWORD PTR _this$[ebp], ecx ;
        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     4                          ;
float C::m(int)const  ENDP

_c$ = -1
_f      PROC
        push    ebp                        ;
        mov     ebp, esp                   ;
        push    ecx                        ;
        push    27                         ; arg 1
        lea     ecx, DWORD PTR _c$[ebp]    ; arg 0 (this ptr) via ecx
        call    float C::m(int)const       ; call C::m()
        mov     esp, ebp                   ;
        pop     ebp                        ;
        ret     0                          ;
_f      ENDP



; output from reactos-0.3.15-x86 w/ mingw gcc 4.7.2 (uses MS thiscalls; according to
; https://www.angelcode.com/dev/callconv/callconv.html MinGW has own thiscalls,
; so maybe ROSBE's MinGW has different behaviour or the web page sources are wong)

00000000 <_f>:
   0:   55                      push   %ebp            ;
   1:   89 e5                   mov    %esp,%ebp       ;
   3:   83 ec 14                sub    $0x14,%esp      ;
   6:   8d 45 ff                lea    -0x1(%ebp),%eax ; this ptr -> eax
   9:   c7 04 24 1b 00 00 00    movl   $0x1b,(%esp)    ; arg 1 via stack
  10:   89 c1                   mov    %eax,%ecx       ; arg 0 (this ptr) via ecx
  12:   e8 00 00 00 00          call   17 <_f+0x17>    ; call C::m()
  17:   83 ec 04                sub    $0x4,%esp       ;
  1a:   c9                      leave                  ;
  1b:   c3                      ret                    ;

00000000 <__ZNK1C1mEi>:
   0:   55                      push   %ebp            ;
   1:   89 e5                   mov    %esp,%ebp       ;
   3:   83 ec 08                sub    $0x8,%esp       ;
   6:   89 4d fc                mov    %ecx,-0x4(%ebp) ;
   9:   8b 45 08                mov    0x8(%ebp),%eax  ;
   c:   83 c0 7b                add    $0x7b,%eax      ; | in arg + 123, pushed onto stack
   f:   89 45 f8                mov    %eax,-0x8(%ebp) ; |
  12:   db 45 f8                fildl  -0x8(%ebp)      ; float cast and put return value in fp0
  15:   c9                      leave                  ;
  16:   c2 04 00                ret    $0x4            ;



; vim: ft=asm