int c = 0;
int i = 0;
for(i =0 ; i< 10; i++)
{
c += i;
}
转化成汇编如下:
mov [ebp - 4], 0 //0000001
mov [ebb - 8], 0 //0000002
mov [ebp - 4], 0 //0000003
jmp 0000006 //0000004
add [ebp -4], 1 //0000005
cmp [ebp-4], 10 //0000006
jge 00000012 //0000007
mov eax, [ebp-8] //0000008
add eax, [ebp-4] //0000009
mov [ebp-8], eax //00000010
jmp 0000005 //00000011
//00000012
Release 版的代码:
00401000 xor eax,eax
00401002 xor ecx,ecx
00401004 add eax,ecx
00401006 inc ecx
00401007 cmp ecx,0Ah
0040100A jl Add+4 (00401004)
C循环与汇编转换
本文探讨了简单的C语言循环代码及其在Debug与Release模式下转换为汇编语言的过程。通过对比两种模式下的汇编指令,揭示了编译器优化对代码的影响。Debug模式下,代码更注重可读性和调试;而Release模式则更加注重性能优化。
209

被折叠的 条评论
为什么被折叠?



