当前位置:网站首页>2020-09-04: do you understand the function call convention?
2020-09-04: do you understand the function call convention?
2020-11-06 21:50:38 【Fuda Dajia architect's daily question】
Fogo's answer 2020-09-04:
Primary answer :
stdcall and cdecl Both parameters are passed from right to left .
The difference is stdcall In the called function (Callee) Return to the former , By the called function (Callee) Adjust the stack .cdecl In the called function (Callee) After the return , By the caller (Caller) Adjust the stack , Every function that calls it contains the code to empty the stack , So the size of the resulting executable is larger than that of the call _stdcall The size of the function .
Intermediate answer :
1.__stdcall
In the called function (Callee) Return to the former , By the called function (Callee) Adjust the stack
Parameters are pushed right to left onto the stack .
The function name is automatically underlined before it , Followed by one @ Symbol , It's followed by the size of the parameter .
2.__cdecl
In the called function (Callee) After the return , By the caller (Caller) Adjust the stack .
Function arguments are stacked on the program stack from right to left .
Function results are stored in registers EAX/AX/AL in
Floating point results are stored in registers ST0 in
The compiled function name is prefixed with an underline character
The caller is responsible for ejecting arguments from the thread stack ( Clear the stack )
8 Bit or 16 The actual parameters of plastic surgery are improved to 32 Better than .
Registers affected by function calls (volatile registers):EAX, ECX, EDX, ST0 - ST7, ES, GS
Registers that are not affected by function calls : EBX, EBP, ESP, EDI, ESI, CS, DS
RET Instruction returns from the callee of the function to the caller ( It's essentially reading registers EBP The return address of the function stored at the thread stack and loaded into IP register )
3.__fastcall
__fastcall The main feature of call is fast , Because it transfers parameters through registers .
actually __fastcall use ECX and EDX Send the first two DWORD Or smaller , The remaining parameters are still pushed from right to left , The called function cleans up the memory stack of the transfer parameters before returning .
__fastcall The calling convention adds a “@” Symbol , There's also a “@” Bytes of symbols and their parameters , The format is @function @number , Such as double multi(double a, double b) The modifier name of is @[email protected]
__fastcall and __stdcall Much like the , The only difference is that the first two parameters are passed through registers . Note that the two parameters passed through the register are left to right , That is to say 1 Parameters in ECX, The first 2 Advance in EDX, Other parameters are right to left push , Return still pass EAX.
fastcall Call Convention and stdcall similar , It means that the :
- The first and second of the function DWORD Parameters ( Or smaller ) adopt ecx and edx Pass on , Other parameters are stacked in order from right to left ;
- The called function cleans the stack ;
- The rules for modifying function names are the same as stdcall.
Fast Calling Convention, Quick call Convention . Solve efficiency problems by using registers . characteristic :
Function parameters are passed through registers , The two leftmost of the functions DWORD( The register size is double word ) Or smaller parameters , Pass... By register . The rest is passed from the right to the left stack . Function name adaptation :“@ Function name @ Function parameter byte size decimal ”. Return in the same way __stdcall.
4.__thiscall
thiscall Is the only functional modifier that can't be specified , because thiscall Not a keyword . It is C++ The default calling convention of class member function . Because the member function call has another this The pointer , Therefore, special treatment is necessary ,thiscall signify :
- Parameters are pushed from right to left ;
- If the number of parameters is determined ,this Pointer through ecx Pass to callee ; If the number of parameters is uncertain ,this The pointer is pushed onto the stack after all parameters are pushed onto the stack ;
- Variable number of parameters , The caller cleans the stack , Otherwise, the function cleans the stack itself .
Mainly used to solve this Pointer problem , Use registers to pass this The pointer . Return in the same way __stdcall.
5.__nakedcall
This is a very rare calling convention , General programmers recommend not to use . The compiler does not add initialization and cleanup code to this function , What's more special , Out-of-service return Return return value , Only insert assembly can return the result .
6.__pascal
be based on Pascal Call convention of language , Parameters are put on the stack from left to right ( And cdecl contrary ). The callee is responsible for cleaning the stack before returning . This calling convention is common in the following 16-bit The compiler for the platform :OS/2 1.x, Microsoft Windows 3.x, as well as Borland Delphi edition 1.x.
7.__vectorcall
The purpose is to optimize floating-point vector operations ,intel There are many floating-point vector registers in the processor , The traditional calling convention (stdcall cdecl fastcall thiscall) All through general registers (ecx edx /rcx rdx r8 r9) And stack for parameter passing , So when you call it , Floating point parameters need to be taken from the stack .
It is required to pass parameters in registers as much as possible . The function name is adapted to ”@@ Function name @ Parameter byte number decimal ”. This is Microsoft's own standard .
8.syscall
And cdecl similar , Arguments are pushed right to left onto the stack .EAX, ECX and EDX Values are not preserved . The size of the parameter list is placed in AL In the register (?). syscall yes 32 position OS/2 API Standards for .
9.optlink
Parameters are also pushed onto the stack from right to left . The three character arguments starting from the far left are placed in EAX, EDX and ECX in , Up to four floating-point arguments are passed in ST(0) To ST(3) in ---- Although the space of these four parameters will be reserved on the stack of parameter list . The return value of the function is in EAX or ST(0) in . The Reserved registers are EBP, EBX, ESI and EDI. optlink stay IBM VisualAge It is used in compilers .
10.__clrcall
__clrcall yes C++ .Net Inside .
版权声明
本文为[Fuda Dajia architect's daily question]所创,转载请带上原文链接,感谢
边栏推荐
- C++ 数字、string和char*的转换
- C++学习——centos7上部署C++开发环境
- C++学习——一步步学会写Makefile
- C++学习——临时对象的产生与优化
- C++学习——对象的引用的用法
- C++编程经验(6):使用C++风格的类型转换
- Won the CKA + CKS certificate with the highest gold content in kubernetes in 31 days!
- C + + number, string and char * conversion
- C + + Learning -- capacity() and resize() in C + +
- C + + Learning -- about code performance optimization
猜你喜欢
-
C + + programming experience (6): using C + + style type conversion
-
Latest party and government work report ppt - Park ppt
-
在线身份证号码提取生日工具
-
Online ID number extraction birthday tool
-
️野指针?悬空指针?️ 一文带你搞懂!
-
Field pointer? Dangling pointer? This article will help you understand!
-
HCNA Routing&Switching之GVRP
-
GVRP of hcna Routing & Switching
-
Seq2Seq实现闲聊机器人
-
【闲聊机器人】seq2seq模型的原理
随机推荐
- LeetCode 91. 解码方法
- Seq2seq implements chat robot
- [chat robot] principle of seq2seq model
- Leetcode 91. Decoding method
- HCNA Routing&Switching之GVRP
- GVRP of hcna Routing & Switching
- HDU7016 Random Walk 2
- [Code+#1]Yazid 的新生舞会
- CF1548C The Three Little Pigs
- HDU7033 Typing Contest
- HDU7016 Random Walk 2
- [code + 1] Yazid's freshman ball
- CF1548C The Three Little Pigs
- HDU7033 Typing Contest
- Qt Creator 自动补齐变慢的解决
- HALCON 20.11:如何处理标定助手品质问题
- HALCON 20.11:标定助手使用注意事项
- Solution of QT creator's automatic replenishment slowing down
- Halcon 20.11: how to deal with the quality problem of calibration assistant
- Halcon 20.11: precautions for use of calibration assistant
- “十大科学技术问题”揭晓!|青年科学家50²论坛
- "Top ten scientific and technological issues" announced| Young scientists 50 ² forum
- 求反转链表
- Reverse linked list
- js的数据类型
- JS data type
- 记一次文件读写遇到的bug
- Remember the bug encountered in reading and writing a file
- 单例模式
- Singleton mode
- 在这个 N 多编程语言争霸的世界,C++ 究竟还有没有未来?
- In this world of N programming languages, is there a future for C + +?
- es6模板字符
- js Promise
- js 数组方法 回顾
- ES6 template characters
- js Promise
- JS array method review
- 【Golang】️走进 Go 语言️ 第一课 Hello World
- [golang] go into go language lesson 1 Hello World