Star引擎中一处代码简化
利用三个平常很少用到的寄存器 EBX ESI EDI 来存储局部变量
既可以节省空间 又可以提高速度(不过这个提高 确实不可能明显感觉出来)
004CFDCA 55 PUSH EBP
004CFDCB 8BEC MOV EBP,ESP
004CFDCD 51 PUSH ECX
004CFDCE 53 PUSH EBX
004CFDCF 56 PUSH ESI
004CFDD0 57 PUSH EDI
004CFDD1 33F6 XOR ESI,ESI
004CFDD3 33FF XOR EDI,EDI
004CFDD5 E8 57C4F3FF CALL Ekd5.0040C231
004CFDDA 0FB6D8 MOVZX EBX,AL
004CFDDD EB 01 JMP SHORT Ekd5.004CFDE0
004CFDDF 46 INC ESI
004CFDE0 81FE 00040000 CMP ESI,400
004CFDE6 73 1D JNB SHORT Ekd5.004CFE05
004CFDE8 56 PUSH ESI
004CFDE9 E8 C116F5FF CALL Ekd5.004214AF
004CFDEE 5A POP EDX
004CFDEF 85C0 TEST EAX,EAX
004CFDF1 74 10 JE SHORT Ekd5.004CFE03
004CFDF3 E8 D867F3FF CALL Ekd5.004065D0
004CFDF8 3AC3 CMP AL,BL
004CFDFA 73 07 JNB SHORT Ekd5.004CFE03
004CFDFC 8B45 FC MOV EAX,DWORD PTR SS:[EBP-4]
004CFDFF 890CB8 MOV DWORD PTR DS:[EAX+EDI*4],ECX
004CFE02 47 INC EDI
004CFE03 ^ EB DA JMP SHORT Ekd5.004CFDDF
004CFE05 8B4D FC MOV ECX,DWORD PTR SS:[EBP-4]
004CFE08 99 CDQ
004CFE09 8914B9 MOV DWORD PTR DS:[ECX+EDI*4],EDX
004CFE0C 8AD3 MOV DL,BL
004CFE0E 8BC7 MOV EAX,EDI
004CFE10 5F POP EDI
004CFE11 5E POP ESI
004CFE12 5B POP EBX
004CFE13 8BE5 MOV ESP,EBP
004CFE15 5D POP EBP
004CFE16 C3 RETN
004CFE17 CC INT3
同一段不用寄存器的代码
004CFDCA 55 PUSH EBP
004CFDCB 8BEC MOV EBP,ESP
004CFDCD 83EC 10 SUB ESP,10
004CFDD0 894D FC MOV DWORD PTR SS:[EBP-4],ECX
004CFDD3 33C0 XOR EAX,EAX
004CFDD5 8945 F8 MOV DWORD PTR SS:[EBP-8],EAX
004CFDD8 8945 F0 MOV DWORD PTR SS:[EBP-10],EAX
004CFDDB E8 51C4F3FF CALL Ekd5_jin.0040C231
004CFDE0 8845 F4 MOV BYTE PTR SS:[EBP-C],AL
004CFDE3 EB 03 JMP SHORT Ekd5_jin.004CFDE8
004CFDE5 FF45 F8 INC DWORD PTR SS:[EBP-8]
004CFDE8 817D F8 0004000>CMP DWORD PTR SS:[EBP-8],400
004CFDEF 73 27 JNB SHORT Ekd5_jin.004CFE18
004CFDF1 FF75 F8 PUSH DWORD PTR SS:[EBP-8]
004CFDF4 E8 B616F5FF CALL Ekd5_jin.004214AF
004CFDF9 83C4 04 ADD ESP,4
004CFDFC 85C0 TEST EAX,EAX
004CFDFE 74 16 JE SHORT Ekd5_jin.004CFE16
004CFE00 E8 CB67F3FF CALL Ekd5_jin.004065D0
004CFE05 3A45 F4 CMP AL,BYTE PTR SS:[EBP-C]
004CFE08 73 0C JNB SHORT Ekd5_jin.004CFE16
004CFE0A 8B45 FC MOV EAX,DWORD PTR SS:[EBP-4]
004CFE0D 8B55 F0 MOV EDX,DWORD PTR SS:[EBP-10]
004CFE10 890C90 MOV DWORD PTR DS:[EAX+EDX*4],ECX
004CFE13 FF45 F0 INC DWORD PTR SS:[EBP-10]
004CFE16 ^ EB CD JMP SHORT Ekd5_jin.004CFDE5
004CFE18 8B4D FC MOV ECX,DWORD PTR SS:[EBP-4]
004CFE1B 8B45 F0 MOV EAX,DWORD PTR SS:[EBP-10]
004CFE1E 33D2 XOR EDX,EDX
004CFE20 891481 MOV DWORD PTR DS:[ECX+EAX*4],EDX
004CFE23 8A55 F4 MOV DL,BYTE PTR SS:[EBP-C]
004CFE26 8BE5 MOV ESP,EBP
004CFE28 5D POP EBP
004CFE29 C3 RETN
用二进制来比较长度
寄存器
55 8B EC 51 53 56 57 33 F6 33 FF E8 57 C4 F3 FF 0F B6 D8 EB 01 46 81 FE 00 04 00 00 73 1D 56 E8
C1 16 F5 FF 5A 85 C0 74 10 E8 D8 67 F3 FF 3A C3 73 07 8B 45 FC 89 0C B8 47 EB DA 8B 4D FC 99 89
14 B9 8A D3 8B C7 5F 5E 5B 8B E5 5D C3
非寄存器
55 8B EC 83 EC 10 89 4D FC 33 C0 89 45 F8 89 45 F0 E8 51 C4 F3 FF 88 45 F4 EB 03 FF 45 F8 81 7D
F8 00 04 00 00 73 27 FF 75 F8 E8 B6 16 F5 FF 83 C4 04 85 C0 74 16 E8 CB 67 F3 FF 3A 45 F4 73 0C
8B 45 FC 8B 55 F0 89 0C 90 FF 45 F0 EB CD 8B 4D FC 8B 45 F0 33 D2 89 14 81 8A 55 F4 8B E5 5D C3
大概短了多少字节 可以看得出来吧 至少15%是有的
[ 本帖最后由 砖家叫兽 于 2012-4-21 11:51 编辑 ]
|