//for 反汇编 #include<stdio.h> int main() { int i=0; int s=0; for(i=10;i<20;i++) { s=s+1; } s=0; for(i=10;i>=1;i--) { s=s+1; } return 0; }
//for 反汇编 #include<stdio.h> int main() { 000000013F1231E0 push rdi 000000013F1231E2 sub rsp,10h 000000013F1231E6 mov rdi,rsp 000000013F1231E9 mov ecx,4 000000013F1231EE mov eax,0CCCCCCCCh 000000013F1231F3 rep stos dword ptr [rdi] int i=0; 000000013F1231F5 mov dword ptr [rsp],0 int s=0; 000000013F1231FC mov dword ptr [s],0 for(i=10;i<20;i++) 000000013F123204 mov dword ptr [rsp],0Ah 000000013F12320B jmp main+35h (013F123215h) 000000013F12320D mov eax,dword ptr [rsp] 000000013F123210 inc eax 000000013F123212 mov dword ptr [rsp],eax 000000013F123215 cmp dword ptr [rsp],14h ; i>=20 则跳出循环 000000013F123219 jge main+47h (013F123227h) { s=s+1; 000000013F12321B mov eax,dword ptr [s] 000000013F12321F inc eax 000000013F123221 mov dword ptr [s],eax } 000000013F123225 jmp main+2Dh (013F12320Dh) s=0; 000000013F123227 mov dword ptr [s],0 for(i=10;i>=1;i--) 000000013F12322F mov dword ptr [rsp],0Ah for(i=10;i>=1;i--) 000000013F123236 jmp main+60h (013F123240h) 000000013F123238 mov eax,dword ptr [rsp] 000000013F12323B dec eax 000000013F12323D mov dword ptr [rsp],eax 000000013F123240 cmp dword ptr [rsp],1 ;小于则跳出循环 000000013F123244 jl main+72h (013F123252h) { s=s+1; 000000013F123246 mov eax,dword ptr [s] 000000013F12324A inc eax 000000013F12324C mov dword ptr [s],eax } 000000013F123250 jmp main+58h (013F123238h) return 0; 000000013F123252 xor eax,eax } 000000013F123254 add rsp,10h 000000013F123258 pop rdi 000000013F123259 ret
图片来自:《天书夜读 从汇编语言到windows内核编程》 作者:谭文 邵坚磊
如果是release版,for被优化,模仿do-while语句,把跳转判断以及限制变量的改变放在结尾处。
struct寻址:
在c反汇编中,结构与枚举、联合没有差别。