# HG changeset patch # User Tassilo Philipp # Date 1664633640 -7200 # Node ID 516d72e982539c52988e773a53a2021ff231c9eb # Parent b74d7a249642c66ee9f06bae9b2274e9e961bfb9 - more thiscall disas examples diff -r b74d7a249642 -r 516d72e98253 doc/disas_examples/x86.thiscall.disas --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/doc/disas_examples/x86.thiscall.disas Sat Oct 01 16:14:00 2022 +0200 @@ -0,0 +1,73 @@ +; ---------- simple C++ thiscall ----------> +; +; class C { +; public: +; float m(int i) const { return float(i + 123); } +; }; +; +; extern "C" { +; float f() +; { +; C c; +; return c.m(27); +; } +; } + + + +; output from openbsd-4.0-x86 w/ gcc 3.3.5 (propolice) + +00000000 : + 0: 55 push %ebp ; | + 1: 89 e5 mov %esp,%ebp ; | prolog + 3: 83 ec 08 sub $0x8,%esp ; / + 6: 83 ec 08 sub $0x8,%esp ; + 9: 6a 1b push $0x1b ; arg 1 + b: 8d 45 ff lea 0xffffffff(%ebp),%eax ; | + e: 50 push %eax ; | arg 0 (this ptr) + f: e8 fc ff ff ff call 10 ; call C::m() + 14: 83 c4 10 add $0x10,%esp ; + 17: c9 leave ; + 18: c3 ret ; + +00000000 <_ZNK1C1mEi>: + 0: 55 push %ebp ; + 1: 89 e5 mov %esp,%ebp ; + 3: 8b 45 0c mov 0xc(%ebp),%eax ; | + 6: 83 c0 7b add $0x7b,%eax ; | in arg + 123, pushed onto stack + 9: 50 push %eax ; | + a: db 04 24 fildl (%esp) ; float cast and put return value in fp0 + d: 8d 64 24 04 lea 0x4(%esp),%esp ; + 11: c9 leave ; + 12: c3 ret ; + + + +; output from minix-3.1.8-x86 w/ gcc 4.4.3 + +00000000 <__ZNK1C1mEi>: + 0: 55 push %ebp ; + 1: 89 e5 mov %esp,%ebp ; + 3: 83 ec 18 sub $0x18,%esp ; + 6: 8b 45 0c mov 0xc(%ebp),%eax ; | + 9: 83 c0 7b add $0x7b,%eax ; | in arg + 123, pushed onto stack + c: 89 04 24 mov %eax,(%esp) ; | + f: e8 ec ff ff ff call 0 <__ZNK1C1mEi> ; ? unsure + 14: c9 leave ; + 15: c3 ret ; note: float returned via eax + +00000016 <_f>: + 16: 55 push %ebp ; + 17: 89 e5 mov %esp,%ebp ; + 19: 83 ec 28 sub $0x28,%esp ; + 1c: c7 44 24 04 1b 00 00 00 movl $0x1b,0x4(%esp) ; arg 1 via stack + 24: 8d 45 f7 lea 0xfffffff7(%ebp),%eax ; | + 27: 89 04 24 mov %eax,(%esp) ; | arg 0 (this ptr) + 2a: e8 d1 ff ff ff call 0 <__ZNK1C1mEi> ; call C::m() + 2f: c9 leave ; + 30: c3 ret ; + + + +; vim: ft=asm + diff -r b74d7a249642 -r 516d72e98253 doc/disas_examples/x86.thiscall_ms.disas --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/doc/disas_examples/x86.thiscall_ms.disas Sat Oct 01 16:14:00 2022 +0200 @@ -0,0 +1,84 @@ +; 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 +