calling-convention

What's the equivalent of BP register ( Frame Pointer ) on ARM processors?

给你一囗甜甜゛ 提交于 2019-12-04 23:30:20
问题 On intel platforms, BP is used to point to the beginning of the stack frame and to access the arguments [bp+0x??] and local variables [bp-0x??] . Which register is used in ARM? Or, is the addressing based on SP only? [I don't have infrastructure to compile and disassemble to see it by myself. Referring to AAPCS did not help me either] 回答1: What you are looking for is the Frame Pointer. Generally, R7 acts as the frame pointer in THUMB mode and R11 acts as the frame pointer in ARM mode. But it

Writing naked functions with custom prolog and epilog code in Visual Studio

只愿长相守 提交于 2019-12-04 10:22:48
I'm writing some plugin code in a dll that is called by a host over which I have no control. The host assumes that the plugins are exported as __stdcall functions. The host is told the name of the function and the details of the arguments that it expects and dynamically crufts up a call to it via LoadLibrary, GetProcAddress and manually pushing the arguments onto the stack. Usually plugin dlls expose a constant interface. My plugin exposes an interface that is configured at dll load time. To achieve this my plugin exposes a set of standard entry points that are defined at the time the dll is

__cdecl and __declspec calling conventions confusion

泪湿孤枕 提交于 2019-12-04 05:46:26
I am writing a DLL for a third party application. The main software engineer mentions that the application uses the __cdecl (/Gd) calling convention. That I need to make sure that I use that. Additionally, the third party has provided to me a C++ DLL skeleton which exports the functions as follows: #ifdef _EXPORTING #define DECLSPEC __declspec(dllexport) #else #define DECLSPEC __declspec(dllimport) #endif #ifdef __cplusplus extern "C" { #endif DECLSPEC int ICD_Create(char* id); .... .... I am kind of confused. Why the functions are being exported using __declspec convention instead of __cdedl?

Why do we have to dereference stdout here?

烂漫一生 提交于 2019-12-04 05:31:29
问题 I am trying to call fputs(str, stdout); from assembly. Why should I push dword [stdout] instead of just push stdout ? Since in C we don't do fputs(str, *stdout) , why do we need to dereference stdout in assembly? Full code: extern fputs extern stdout section .data hw: db "Hello World!", 10, 0 section .text global main main: enter 0,0 push dword [stdout] ;push stdout push hw call fputs leave mov eax, 0 ret 回答1: You're dereferencing the asm label stdout , which is equivalent to &stdout in C. It

Unable to understand example of cdecl calling convention where caller doesnt need to clean the stack

只愿长相守 提交于 2019-12-04 04:27:20
问题 I am reading the IDA Pro Book. On page 86 while discussing calling conventions, the author shows an example of cdecl calling convention that eliminates the need for the caller to clean arguments off the stack. I am reproducing the code snippet below: ; demo_cdecl(1, 2, 3, 4); //programmer calls demo_cdecl mov [esp+12], 4 ; move parameter z to fourth position on stack mov [esp+8], 3 ; move parameter y to third position on stack mov [esp+4], 2 ; move parameter x to second position on stack mov

What's the default calling convention of a C++ lambda function?

萝らか妹 提交于 2019-12-04 00:36:51
The following code was compiled with VC++ 2012: void f1(void (__stdcall *)()) {} void f2(void (__cdecl *)()) {} void __cdecl h1() {} void __stdcall h2() {} int main() { f1(h1); // error C2664 f2(h2); // error C2664 f1([](){}); // OK f2([](){}); // OK auto fn = [](){}; f1(fn); // OK f2(fn); // OK } I think the errors are normal yet the OKs are abnormal. So, my questions are: What's the calling convention of a C++ lambda function? How to specify the calling convention of a C++ lambda function? If the calling convention is not defined, how to correctly recycle the stack space after having called

Write a Fizz program in assembly / Using C library

拥有回忆 提交于 2019-12-03 18:14:07
问题 Could someone help me with this assembly program: First print out numbers 1 to 100. Then follow the rules for the children's counting game Fizz: whenever the number is evenly divisible by 5, or contains the digit 5, replace the number by the word “Fizz”. This is my program so far: extern printf section .data msg db "Hello, world!",0xa len equ $ - msg fmt: db "a=%d, eax=%d", 10, 0 ; The printf format, "\n",'0' section .text global main main: L1: mov eax,1 push eax call printf cmp eax,100 jae

__cdecl or __stdcall on Windows?

主宰稳场 提交于 2019-12-03 17:53:48
问题 I'm currently developing a C++ library for Windows which will be distributed as a DLL. My goal is to maximize binary interoperability; more precisely, the functions in my DLL must be usable from code compiled with multiple versions of MSVC++ and MinGW without having to recompile the DLL. However, I'm confused about which calling convention is best, cdecl or stdcall. Sometimes I hear statements like "the C calling convention is the only one guaranteed to be the same accross compilers", which

x86_64 calling conventions and stack frames

跟風遠走 提交于 2019-12-03 17:31:03
问题 I am trying to make sense out of the executable code that GCC (4.4.3) is generating for an x86_64 machine running under Ubuntu Linux. In particular, I don't understand how the code keeps track of stack frames. In the old days, in 32-bit code, I was accustomed to seeing this "prologue" in just about every function: push %ebp movl %esp, %ebp Then, at the end of the function, there would come an "epilogue," either sub $xx, %esp # Where xx is a number based on GCC's accounting. pop %ebp ret or

What's the equivalent of BP register ( Frame Pointer ) on ARM processors?

心不动则不痛 提交于 2019-12-03 14:12:26
On intel platforms, BP is used to point to the beginning of the stack frame and to access the arguments [bp+0x??] and local variables [bp-0x??] . Which register is used in ARM? Or, is the addressing based on SP only? [I don't have infrastructure to compile and disassemble to see it by myself. Referring to AAPCS did not help me either] What you are looking for is the Frame Pointer. Generally, R7 acts as the frame pointer in THUMB mode and R11 acts as the frame pointer in ARM mode. But it is under the discretion of the OS to change this convention if it wishes to. Read here 来源: https:/