Delphi-condition-based judgment

Source: Internet
Author: User

Technical Exchange, DH explanation.

I used Delphi to get the next loop body. Now let's get a conditional judgment.
First, it must be the if statement we often see.

 
VaR I: integer; begin I: = 99; if (I> 0) and (I <0) Then writeln ('I> 0') else if (I> 10) and (I <100) Then writeln ('I> 10 and I <100') else writeln ('I> 100'); end.

What will the disassembly look like?

Project5.dpr. 12: I: = 99; 004ac44c b863000000 mov eax, $20170063project5. dpr.13: if (I> 0) and (I <0) then004ac451 85c0 test eax, %7e1f jle $%85c0 test eax, eax004ac457 7d1b JNL $004ac474project5. dpr.14: writeln ('I> 0') 004ac459 a1dc314b00 mov eax, [$ 004b31dc] 004ac45e bac4c44a00 mov edX, $004ac4c4004ac463 e874baf5ff call @ effece8bf89f5ff call @ writeln004ac46d e83e7ff5ff call @ _ iotest004ac472 eb3e JMP $004ac4b2project5. dpr.16: if (I> 10) and (I <100) then004ac474 83f80a CMP eax, $4157e20 jle $41583f864 CMP eax, $ 64004ac47c 7d1b JNL $004ac499project5. dpr.17: writeln ('I> 10 and I <100') 004ac47e a1dc314b00 mov eax, [$ 004b31dc] 004ac483 bad8c44a00 mov edX, $004ac4d8004ac488 e84fbaf5ff call @ javase89a89f5ff call @ writeln004ac492 e8197ff5ff call @ _ iotest004ac497 eb19 JMP $004ac4b2project5. dpr.19: writeln ('I> 100'); 004ac499 a1dc314b00 mov eax, [$ 004b31dc] 004ac49e ba04c54a00 mov edX, $ commandid call @ _ iotest

here we can easily obtain the if statement structure in Delphi.
Judge 1
skip ------------------------- if the condition is not met |
the code that meets the condition |
[unconditionally JMP all external Judgment] |
[Judgment 2] <------ |
...................... .........................
this is the case.
the if disassembly code is similar to the VC disassembly code in the book.
next, let's look at the switch statement (case in Delphi):

VaR I: integer; begin I: = 9; case I of 0: writeln ('0'); 1: writeln ('1'); 2: writeln ('2'); 3: writeln ('3'); 4: writeln ('4'); 5: writeln ('5'); 6: writeln ('6'); 7: writeln ('7'); else writeln ('0'); end.

Disassembly:

Project5.dpr. 12: I: = 9; 004ac44c b809000000 mov eax, $00000009project5. dpr.13: Case I of004ac451 83f807 CMP eax, $07004ac454 0f8703010000 jnbe $ 20.1_jmp DWORD PTR [eax * 4 + $4ac461] 004ac461 limit add ESP, $ 4A dec edx004ac468 notify add [EBX-$ 27ffb53c], bh004ac46e c44a00 les ECx, [edX + $00] 004ac471 F5 CMC 004ac472 c44a00 les ECx, [edX + $00] 004ac475 rjpextrw ECx, qword PTR [edX + $00], $ 29004ac47a c54a00 lDs ECx, [edX + $00] 004ac47d 43 Inc rjc54a00 lDs ECx, [edX + $00] project5.dpr. 15: writeln ('0'); 004ac481 a1dc314b00 mov eax, [$ 004b31dc] 004ac1_66ba3000 mov dx, $ 0030004ac48a e8ddadf5ff call @ effece89889f5ff call @ writeln004ac494 e8177ff5ff call @ _ iotest004ac499 e9d7000000 JMP $004ac575project5. dpr.17: writeln ('1'); 004ac49e a1dc314b00 mov eax, [$ 004b31dc] 004ac4a3 66ba3100 mov dx, $0031004ac4a7 e8c0adf5ff call @ effece87b89f5ff call @ writeln004ac4b1 e8fa7ef5ff call @ _ iotest004ac4b6 e9ba%00 JMP $004ac575project5. dpr.19: writeln ('2'); 004ac4bb a1dc314b00 mov eax, [$ 004b31dc] 004ac4c0 66ba3200 mov dx, $0032004ac4c4 e8a3adf5ff call @ effece85e89f5ff call @ writeln004ac4ce e8dd7ef5ff call @ _ iotest004ac4d3 e99d000000 JMP $004ac575project5. dpr.21: writeln ('3'); 004ac4d8 a1dc314b00 mov eax, [$ 004b31dc] 004ac4dd 66ba3300 mov dx, $0033004ac4e1 e886adf5ff call @ effece84189f5ff call @ writeln004ac4eb e8c07ef5ff call @ _ iotest004ac4f0 e980000000 JMP $004ac575project5. dpr.23: writeln ('4'); 004ac4f5 a1dc314b00 mov eax, [$ 004b31dc] 004ac4fa 66ba3400 mov dx, $ 0034004ac4fe e869adf5ff call @ effece000089f5ff call @ writeln004ac508 e8a37ef5ff call @ _ iotest004ac50d eb66 JMP $004ac575project5. dpr.25: writeln ('5'); 004ac50f a1dc314b00 mov eax, [$ 004b31dc] 004ac514 66ba3500 mov dx, $0035004ac518 e84fadf5ff call @ effece80a89f5ff call @ writeln004ac522 e8897ef5ff call @ _ iotest004ac527 eb4c JMP $004ac575project5. dpr.27: writeln ('6'); 004ac529 a1dc314b00 mov eax, [$ 004b31dc] 004ac52e 66ba3600 mov dx, $0036004ac532 e835adf5ff call @ effece8f088f5ff call @ writeln004ac53c e86f7ef5ff call @ _ iotest004ac541 eb32 JMP $004ac575project5. dpr.29: writeln ('7'); 004ac543 a1dc314b00 mov eax, [$ 004b31dc] 004ac548 66ba3700 mov dx, $ 0037004ac54c e81badf5ff call @ effece8d688f5ff call @ writeln004ac556 e8557ef5ff call @ _ iotest004ac55b eb18 JMP $004ac575project5. dpr.31: writeln ('0'); 004ac55d a1dc314b00 mov eax, [$ 004b31dc] 004ac1_66ba3000 mov dx, $0030004ac566 seconds call @ commandid call @ _ iotest

here we see a Delphi optimization. It first compares I to 7. If it is greater than 7, it directly jumps to the else statement.
if it is less than or equal to, we can see that it is unconditional JMP to a place where I is equal spacing offset, that is, each writeln statement is equal to the size.
what if we change it to 01234567 instead? Let's try it by yourself. It's not the same time case Code or the Code hasn't changed.
what will happen in VC?
CMP-> Je-> CMP-> je
This is the constant comparison. If they are equal, they will jump. this is in line with our thinking.
okay. This book will have an after-school question. haha, I will also do it.
next time I will talk about the structure disassembly.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.