当前位置:网站首页>2. Judgment statement

2. Judgment statement

2022-07-23 10:19:00 Chicken Island~

C++ Code

bool isWorth{
    };
if (isWorth == true) {
    
    std::cout << 1;
}
else {
    
    std::cout << 0;
}

Assembly code

mov         byte ptr [ebp-5],0  

movzx       eax,byte ptr [ebp-5]  
cmp         eax,1  
jne         00A1573E

00795725 mov         esi,esp  
push        1  
mov         ecx,dword ptr ds:[00A210D4h]  
call        dword ptr ds:[00A210DCh]  
cmp         esi,esp  
call        00A113C0

EB 17       jmp         00A15755

mov         esi,esp  
push        0  
mov         ecx,dword ptr ds:[00A210D4h]  
call        dword ptr ds:[00A210DCh]  
cmp         esi,esp  
call        00A113C0  

Machine code

C6 45 FB 00

0F B6 45 FB
83 F8 01
75 19

8B F4
6A 01  
8B 0D D4 10 A2 00
FF 15 DC 10 A2 00
3B F4 
E8 84 BC FF FF

EB 17

8B F4  
6A 00  
8B 0D D4 10 A2 00  
FF 15 DC 10 A2 00 
3B F4 
E8 6B BC FF FF   
Raise questions :
  • cpu Through what mechanism Jump To 00795725 This memory address ?
  • if Why is there a line at the end of the code jmp Instructions ? answer : In order to skip over else The code in the code block , avoid else The code block is executed .

Modify the code


> By modifying a single conditional variable isWorth To observe the changes :
> Found that when isWorth by 1 when , register EFL Nothing will change 
> When isWorth by 0 when , register EFL There is a change .
Design experiments

When we run isWorth by true The program , perform cmp Instructions , Only found TF It has changed

When we run isWorth by false The program , perform cmp Instructions ,ZF, AF, SF, CF,TF There is a change

 Insert picture description here

Found that regular :
  1. cmp Instructions will affect ZF position
  2. When ZF Position as 1 when ,jne Instructions are the same as ordinary instructions , After the execution , Can make EIP The address of +2; When ZF Position as 0 when ,jne Instructions will make EIP The address of
    It is amended as follows jne Address in the instruction , The address in the instruction is else Code inside The first address
Come to the conclusion :
  1. if else The essence of is actually mov, cmp,jne,jmp The combination of instructions
原网站

版权声明
本文为[Chicken Island~]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/204/202207230248468493.html