vc2005 问题二

来源:互联网 发布:如何装饰手机淘宝店铺 编辑:程序博客网 时间:2024/04/29 17:27

上次碰到了优化问题以为是偶然的,今天又碰到了一回

一条类似

 x=new classa();// 返回 x==0
if (!x) goto RELEASE;

生成的代码会是
test eax,eax
mov [x],eax
mov eax,[this]
jz RELEASE

不看asm真的不知道为什么明明是一个值却不得到正确结果

#define RETISNULL(JmpAddr) __asm test eax,eax/
 __asm jz JmpAddr
非优化eax为返回值,优化后....

//----------

 Sessions = new CMemoryPool(sizeof(SESSION),10000);
004025DC 6A 48            push        48h 
004025DE E8 0D EB FF FF   call        operator new (4010F0h)
004025E3 83 C4 04         add         esp,4
004025E6 89 45 D8         mov         dword ptr [ebp-28h],eax
004025E9 83 7D D8 00      cmp         dword ptr [ebp-28h],0
004025ED 74 14            je          CPlantServer::CPlantServer+0A3h (402603h)
004025EF 68 10 27 00 00   push        2710h
004025F4 6A 1C            push        1Ch 
004025F6 8B 4D D8         mov         ecx,dword ptr [ebp-28h]
004025F9 E8 82 09 00 00   call        CMemoryPool::CMemoryPool (402F80h)
004025FE 89 45 C0         mov         dword ptr [ebp-40h],eax
00402601 EB 07            jmp         CPlantServer::CPlantServer+0AAh (40260Ah)
00402603 C7 45 C0 00 00 00 00 mov         dword ptr [ebp-40h],0
0040260A 8B 45 C4         mov         eax,dword ptr [this]
0040260D 8B 4D C0         mov         ecx,dword ptr [ebp-40h]
00402610 89 48 54         mov         dword ptr [eax+54h],ecx

原创粉丝点击