编译原理课程设计之函数调用分析(Compiler theory, curriculum design, function call analysis).doc

上传人:rrsccc 文档编号:8910992 上传时间:2021-01-24 格式:DOC 页数:13 大小:43.50KB
返回 下载 相关 举报
编译原理课程设计之函数调用分析(Compiler theory, curriculum design, function call analysis).doc_第1页
第1页 / 共13页
编译原理课程设计之函数调用分析(Compiler theory, curriculum design, function call analysis).doc_第2页
第2页 / 共13页
编译原理课程设计之函数调用分析(Compiler theory, curriculum design, function call analysis).doc_第3页
第3页 / 共13页
编译原理课程设计之函数调用分析(Compiler theory, curriculum design, function call analysis).doc_第4页
第4页 / 共13页
编译原理课程设计之函数调用分析(Compiler theory, curriculum design, function call analysis).doc_第5页
第5页 / 共13页
点击查看更多>>
资源描述

《编译原理课程设计之函数调用分析(Compiler theory, curriculum design, function call analysis).doc》由会员分享,可在线阅读,更多相关《编译原理课程设计之函数调用分析(Compiler theory, curriculum design, function call analysis).doc(13页珍藏版)》请在三一文库上搜索。

1、编译原理课程设计之函数调用分析(Compiler theory, curriculum design, function call analysis)There are 3 methods for calling functions in Windows systems: _stdcall, _cdecl, PASCALThe first two pass arguments from right to left, and the last is to pass arguments from left to right_stdcall is the standard way for Windo

2、ws systems to call API_cdecl is the standard invocation of ANSI-CThere are some differences between _stdcall and _cdecl:1._stdcall returns the EBP and ESP pointers from the called function, in this case f_stcall ()2._cdecl returns the EBP and ESP pointers by calling functions, in this case f_cdecl (

3、)=#include stdio.hVoid, _stdcall, f_stdcall (int, a, int, b)Int c;C=a+b;Void f_cdeclr (int, a, int, b)Int c;C=a+b;(main)Int, left, =1, right, =2;F_stdcall (left, right);F_cdeclr (left, right);Printf (%d,%d, 1,2);= = =1: #include stdio.h2:=Disassembly of the f_stdcall () function=3:, void, _stdcall,

4、f_stdcall (int, a, int, b)4: 004012F0 push EBP / / main.ebp parent function preservation base004012F1 mov EBP, esp / / open stack f_stdcall.ebp004012F3, sub, esp, 44h, /40h, int, C, 4H004012F6 push ebx / / initialize the 44h space, 11 cycles004012F7 push ESI004012F8 push EDI004012F9, lea, EDI, ebp-4

5、4h004012FC, MOV, ECX, 11h00401301, MOV, eax, 0CCCCCCCCh00401306, Rep, STOs, DWORD, PTR, edi5: int c;6: c=a+b;00401308 mov eax, DWORD PTR ebp+8 a /+8 / / parameters, the reason in the above said0040130B add eax, DWORD PTR ebp+0Ch B / / parameters0040130E, MOV, DWORD, PTR, ebp-4, and eax/ are saved in

6、 C7:00401311 pop EDI00401312 pop ESI00401313 pop ebx00401314, MOV, esp, EBP00401316 pop EBP / / main.ebp recovery00401317 RET 8 /ebp-8-8=Disassembly of the f_cdecl () function=8:9:, void, f_cdeclr (int, a, int, b)10: The base 00401070 push EBP / / save main.ebp00401071 mov EBP, esp / / made to run s

7、tack f_cdecl.ebp00401073 sub ESP, running 44h 44H / / open stack space,00401076 push ebx / / the following code used to initialize00401077 push ESI00401078 push EDI00401079, lea, EDI, ebp-44h, /ebp-44h=esp0040107C, MOV, ECX, 11h00401081, MOV, eax, 0CCCCCCCCh00401086, Rep, STOs, DWORD, PTR, edi11: in

8、t c;12: c=a+b;00401088 mov eax, DWORD PTR ebp+8 / / A0040108B add eax, DWORD PTR ebp+0Ch / / b0040108E mov DWORD PTR ebp-4, eax / / stored in C13:00401091 pop EDI00401092 pop ESI00401093 pop ebx00401094, MOV, esp, EBP00401096 pop EBP / / recovery site00401097 RET / ebp-8 return=Disassembly of the ma

9、in () function=14:15:, main ()16: 00401320 push EBP / (cmd.exe call stack storage base entrance)00401321 mov EBP, esp / / open stack operation00401323, sub, esp, 48h, /40H reservations, and int left, int, /right, 8H bytes00401326 push ebx / / initialize the 48H space, 12 cycles00401327 push ESI00401

10、328 push EDI00401329, lea, EDI, ebp-48h0040132C, MOV, ECX, 12h00401331, MOV, eax, 0CCCCCCCCh00401336, Rep, STOs, DWORD, PTR, edi17:, int, left, =1, right, =2;00401338, MOV, DWORD, PTR, ebp-4, 1, /ebp-4=left, ebp-8=right0040133F, MOV, DWORD, PTR, ebp-8, 218: f_stdcall (left, right);00401346, MOV, eax

11、, DWORD, PTR, ebp-800401349 push eax / / right press0040134A, MOV, ECX, DWORD, PTR, ebp-40040134D push ECX / / left press0040134E call ILT+15 (_f_stdcall8) (00401014)19: f_cdeclr (left, right); / / call _cdecl00401353 mov EDX, DWORD PTR ebp-8 / / right press00401356 push EDX00401357 mov eax, DWORD P

12、TR ebp-4 / / left press0040135A push eax0040135B, call, ILT+10 (_f_cdeclr) (0040100f)00401360 add ESP, 820: printf (%d,%d, 1,2);004010F3 push 2 / / press 2004010F5 push 1 / / press 1004010F7, push, offset, string,%d,%d (0042001c)004010FC call printf (00401130)00401101, add, esp, 0Ch21:00401104 pop E

13、DI00401105 pop ESI00401106 pop ebx00401107, add, esp, 48h, /main, empty your space, adjust the stack0040110A, CMP, EBP, ESP0040110C call _chkesp (004011b0)00401111, MOV, esp, EBP00401113 pop EBP00401114 ret=Printf:00401130 push EBP00401131, MOV, EBP, ESP00401133, sub, esp, 0Ch, /12 bytes, 1,2, and%d

14、,%d addresses00401136 push ebx00401137 push ESI00401138 push EDI00401139, lea, eax, ebp+0Ch, /ebp+0Ch is the address of %d,%d0040113C mov DWORD PTR arglist, eax / / get the parameter listThe following code is / / analysis parameter list0040113F, CMP, DWORD, PTR, format, 000401143 jne printf+33h (004

15、01163)00401145, push, offset, string, format = = NULL (00420030)0040114A push 00040114C push 36h0040114E, push, offset, string, printf.c (00420024)00401153 push 200401155 call _CrtDbgReport (004026a0)0040115A, add, esp, 14h0040115D, CMP, eax, 100401160 jne printf+33h (00401163)00401162 int 300401163

16、, XOR, ECX, ECX00401165 test ecx, ecx00401167 jne printf + 0fh (0040113f)00401169 push offset _ _ iob + 20h (00422a60)0040116e call _ stbuf (00401380)00401173 add esp, 400401176 mov dword ptr buffing, eax00401179 mov edx, dword ptr (arglist)0040117c push edx0040117d mov eax, dword ptr format00401180

17、 push eax00401181 push offset _ _ iob + 20h (00422a60)00401186 call _ output (004015a0)/ / 这里最后是调用输出函数0040118b add esp, oh0040118e mov dword ptr retval, eax00401191 push offset _ _ iob + 20h (00422a60)00401196 mov ecx, dword ptr buffing00401199 push ecx0040119a call _ ftbuf (004014e0)0040119f add esp, 8004011a2 mov eax, dword ptr retval / / 这是返回值004011a5 pop edi004011a6 pop esi004011a7 pop ebx004011a8 mov esp, ebp004011aa pop ebp004011ab ret

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 社会民生


经营许可证编号:宁ICP备18001539号-1