CÓïÑÔº¯Êýµ÷ÓÃÔ¼¶¨
תÔØ×Ô£º
Ü°ÈÙ¼ÒÔ°blog
ÔÚCÓïÑÔÖУ¬¼ÙÉèÎÒÃÇÓÐÕâÑùµÄÒ»¸öº¯Êý£º
int function(int a,int b)
µ÷
ÓÃʱֻҪÓÃresult =
function(1,2)ÕâÑùµÄ·½Ê½¾Í¿ÉÒÔʹÓÃÕâ¸öº¯Êý¡£µ«ÊÇ£¬µ±¸ß¼¶ÓïÑÔ±»±àÒë³É¼ÆËã»ú¿ÉÒÔʶ±ðµÄ»úÆ÷Âëʱ£¬ÓÐÒ»¸öÎÊÌâ¾Í͹ÏÖ³öÀ´£ºÔÚCPUÖУ¬¼ÆËã
»úûÓа취֪µÀÒ»¸öº¯Êýµ÷ÓÃÐèÒª¶àÉÙ¸ö¡¢Ê²Ã´ÑùµÄ²ÎÊý£¬Ò²Ã»ÓÐÓ²¼þ¿ÉÒÔ±£´æÕâЩ²ÎÊý¡£Ò²¾ÍÊÇ˵£¬¼ÆËã»ú²»ÖªµÀÔõô¸øÕâ¸öº¯Êý´«µÝ²ÎÊý£¬´«µÝ²ÎÊýµÄ¹¤×÷±ØÐë
Óɺ¯Êýµ÷ÓÃÕߺͺ¯Êý±¾ÉíÀ´Ðµ÷¡£Îª´Ë£¬¼ÆËã»úÌṩÁËÒ»ÖÖ±»³ÆΪջµÄÊý¾Ý½á¹¹À´Ö§³Ö²ÎÊý´«µÝ¡£
Õ»ÊÇÒ»ÖÖÏȽøºó³öµÄÊý¾Ý½á¹¹£¬Õ»ÓÐÒ»¸ö´æ´¢Çø¡¢
Ò»¸öÕ»¶¥Ö¸Õë¡£Õ»¶¥Ö¸ÕëÖ¸Ïò¶ÑÕ»ÖеÚÒ»¸ö¿ÉÓõÄÊý¾ÝÏ±»³ÆΪջ¶¥£©¡£Óû§¿ÉÒÔÔÚÕ»¶¥ÉÏ·½ÏòÕ»ÖмÓÈëÊý¾Ý£¬Õâ¸ö²Ù×÷±»³ÆΪѹջ(Push)£¬Ñ¹Õ»ÒÔºó£¬Õ»
¶¥×Ô¶¯±ä³ÉмÓÈëÊý¾ÝÏîµÄλÖã¬Õ»¶¥Ö¸ÕëÒ²ËæÖ®Ð޸ġ£Óû§Ò²¿ÉÒÔ´Ó¶ÑÕ»ÖÐÈ¡×ßÕ»¶¥£¬³ÆΪµ¯³öÕ»(pop)£¬µ¯³öÕ»ºó£¬Õ»¶¥ÏµÄÒ»¸öÔªËرä³ÉÕ»¶¥£¬Õ»¶¥Ö¸Õë
ËæÖ®Ð޸ġ£
º¯Êýµ÷ÓÃʱ£¬µ÷ÓÃÕßÒÀ´Î°Ñ²ÎÊýѹջ£¬È»ºóµ÷Óú¯Êý£¬º¯Êý±»µ÷ÓÃÒÔºó£¬ÔÚ¶ÑÕ»ÖÐÈ¡µÃÊý¾Ý£¬²¢½øÐмÆËã¡£º¯Êý¼ÆËã½áÊøÒԺ󣬻òÕßµ÷ÓÃÕß¡¢»òÕߺ¯Êý±¾ÉíÐ޸ĶÑÕ»£¬Ê¹¶ÑÕ»»Ö¸´Ô×°¡£
ÔÚ²ÎÊý´«µÝÖУ¬ÓÐÁ½¸öºÜÖØÒªµÄÎÊÌâ±ØÐëµÃµ½Ã÷ȷ˵Ã÷£º
µ±²ÎÊý¸öÊý¶àÓÚÒ»¸öʱ£¬°´ÕÕʲô˳Ðò°Ñ²ÎÊýѹÈë¶ÑÕ»
º¯Êýµ÷Óúó£¬ÓÉËÀ´°Ñ¶ÑÕ»»Ö¸´Ô×°
Ôڸ߼¶ÓïÑÔÖУ¬Í¨¹ýº¯Êýµ÷ÓÃÔ¼¶¨À´ËµÃ÷ÕâÁ½¸öÎÊÌâ¡£³£¼ûµÄµ÷ÓÃÔ¼¶¨ÓУº
stdcall
cdecl
fastcall
thiscall
naked call
stdcallµ÷ÓÃÔ¼¶¨
stdcall
ºÜ¶àʱºò±»³ÆΪpascalµ÷ÓÃÔ¼¶¨£¬ÒòΪpascalÊÇÔçÆںܳ£¼ûµÄÒ»ÖÖ½ÌѧÓüÆËã»ú³ÌÐòÉè¼ÆÓïÑÔ£¬ÆäÓï·¨ÑϽ÷£¬Ê¹Óõĺ¯Êýµ÷ÓÃÔ¼¶¨¾ÍÊÇ
stdcall¡£ÔÚMicrosoft
C++ϵÁеÄC/C++±àÒëÆ÷ÖУ¬³£³£ÓÃPASCALºêÀ´ÉùÃ÷Õâ¸öµ÷ÓÃÔ¼¶¨£¬ÀàËƵĺ껹ÓÐWINAPIºÍCALLBACK¡£
stdcallµ÷ÓÃÔ¼¶¨ÉùÃ÷µÄÓ﷨Ϊ(ÒÔÇ°ÎĵÄÄǸöº¯ÊýΪÀý£©£º
int __stdcall
function(int a,int b)
stdcallµÄµ÷ÓÃÔ¼¶¨Òâζ×Å£º1£©²ÎÊý´ÓÓÒÏò×óѹÈë¶ÑÕ»£¬2£©º¯Êý×ÔÉíÐ޸ĶÑÕ» 3)º¯ÊýÃû×Ô¶¯¼ÓÇ°µ¼µÄÏ»®Ïߣ¬ºóÃæ½ô¸úÒ»¸ö@·ûºÅ£¬Æäºó½ô¸ú×ŲÎÊýµÄ³ß´ç
ÒÔÉÏÊöÕâ¸öº¯ÊýΪÀý£¬²ÎÊýbÊ×Ïȱ»Ñ¹Õ»£¬È»ºóÊDzÎÊýa£¬º¯Êýµ÷ÓÃfunction(1,2)µ÷Óô¦·Òë³É»ã±àÓïÑÔ½«±ä³É£º
push 2 µÚ¶þ¸ö²ÎÊýÈëÕ»
push 1 µÚÒ»¸ö²ÎÊýÈëÕ»
call function µ÷ÓòÎÊý£¬×¢Òâ´Ëʱ×Ô¶¯°Ñcs:eipÈëÕ»
¶ø¶ÔÓÚº¯Êý×ÔÉí£¬Ôò¿ÉÒÔ·ÒëΪ£º
push ebp ±£´æebp¼Ä´æÆ÷£
Ïà¹ØÎĵµ£º
Ò»£º×Ö·û´®ÀàÐÍ·ÖÀࣺ
1. C·ç¸ñ×Ö·û´®£ºÆðÔ´ÓÚC£¬²¢ÔÚC++Öеõ½Ö§³Ö¡£
a. ´æ´¢·½Ê½£º±»´æ´¢ÔÚÒ»¸ö×Ö·ûÊý×éÖУ¬Í¨¹ýÒ»¸öchar*ÀàÐ͵ÄÖ¸ÕëÀ´²Ù×ÝËü¡£
b. ÌṩµÄ¿âº¯Êý£º°üº¬Í·Îļþ£º#include<cstring> ......
LuaÓëC½»»¥ÈëÃÅ
¼ò½é
LuaÓëC/C++½áºÏÊǺܽôÃܵÄ, LuaÓëC++½»»¥Êǽ¨Á¢ÔÚLuaÓëCµÄ»ù´¡ÉϵÄ, Ëù
ÒÔżÏÈ´ÓLuaÓëC½²Æð.
ÕýÈçµÚÒ»½²Ëù˵, ÔËÐÐLua³ÌÐò»òÕß˵µ÷ÓÃLuaÖ÷ÒªÓÐÁ½ÖÖ·½Ê½:
* ͨ¹ýÃüÁîÐÐÖ´ÐÐ"Lua"ÃüÁî
* ͨ¹ýLuaµÄC¿â
ËäÈ»´ËǰżÃÇÒ»Ö±ÓõÚÒ»ÖÖ·½Ê½, µ«Å¼Òª¸æËßÄã, ͨ¹ýLuaµÄC¿âÖ´ÐвÅÊÇÓÎÏ·ÖÐ
³£Óõķ½Ê½. ......
¡¾Àý8.6¡¿HanoiËþÎÊÌâ
Ò»¿é°åÉÏÓÐÈý¸ùÕ룬A£¬B£¬C¡£AÕëÉÏÌ×ÓÐ64¸ö´óС²»µÈµÄÔ²ÅÌ£¬´óµÄÔÚÏ£¬Ð¡µÄÔÚÉÏ¡£Èçͼ5.4Ëùʾ¡£Òª°ÑÕâ64¸öÔ²ÅÌ´ÓAÕëÒƶ¯CÕëÉÏ£¬Ã¿´ÎÖ»ÄÜÒƶ¯Ò»¸öÔ²ÅÌ£¬Òƶ¯¿ÉÒÔ½èÖúBÕë½øÐС£µ«ÔÚÈκÎʱºò£¬ÈκÎÕëÉϵÄÔ²Å̶¼±ØÐë±£³Ö´óÅÌÔÚÏ£¬Ð¡ÅÌÔÚÉÏ¡£ÇóÒƶ¯µÄ²½Öè¡£
±¾ÌâËã·¨·ÖÎöÈçÏ£¬ÉèAÉÏ ......
Ö¸ÕëÊÇ£ÃÓïÑÔÖй㷺ʹÓõÄÒ»ÖÖÊý¾ÝÀàÐÍ¡£ÔËÓÃÖ¸Õë±à³ÌÊÇ£ÃÓïÑÔ×îÖ÷ÒªµÄ·ç¸ñÖ®Ò»¡£ÀûÓÃÖ¸Õë±äÁ¿¿ÉÒÔ±íʾ¸÷ÖÖÊý¾Ý½á¹¹£»Äܷܺ½±ãµØʹÓÃÊý×éºÍ×Ö·û´®£»²¢ÄÜÏó»ã±àÓïÑÔÒ»Ñù´¦ÀíÄÚ´æµØÖ·£¬´Ó¶ø±à³ö¾«Á·¶ø¸ßЧµÄ³ÌÐò¡£Ö¸Õ뼫´óµØ·á¸»ÁË£ÃÓïÑԵŦÄÜ¡£Ñ§Ï°Ö¸ÕëÊÇѧϰ£ÃÓïÑÔÖÐ×îÖØÒªµÄÒ»»·£¬ÄÜ·ñÕýÈ·Àí½âºÍʹÓÃÖ¸ÕëÊÇÎÒÃÇÊÇ·ñÕÆÎÕ ......
ÎÒÊÇÒ»¸ö¼ÆËã»úרҵµÄ±¾¿ÆÉú£¬ÏÖÔÚÎÒÃǸոÕѧÍêÁËÊý¾Ý½á¹¹¡£¾Ý˵Êý¾Ý½á¹¹¶ÔÓÚÎÒÃDZà³ÌºÜÖØÒª£¬¿ÉÊÇÎÒÏÖÔÚ²»ÖªÔõô°ÑÊý¾Ý½á¹¹ºÍCÓïÑÔ½áºÏÆðÀ´£¬ÒÔ±ã¸üºÃµÄ½øÐÐcÓïÑÔ±à³Ì¡£ÓÐÄÄλ¸ßÊÖÖ¸µãÒ»¶þ£¬ÔÚÏ¸м¤²»¾¡£¡
......