How to realize switch disassembly in C language
This article mainly introduces "how to realize switch disassembly in c language". In daily operation, I believe many people have doubts about how to realize switch disassembly in c language. The editor has consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to realize switch disassembly in c language". Next, please follow the editor to study!
When there are more branches, the efficiency of switch is higher than that of if. We can see the reason for the high efficiency in disassembly.
1. Switch statement 1. When forward coding, switch statement can be regarded as the abbreviation of if statement.
2. Ingenious use of break in switch statement
1. When there are three branches in switch
When break is removed,
2. Disassembly of switch statements 1. When there are three branches of switch, # includevoid Function (int x) {switch (x) {case 1: printf ("1"); case 2: printf ("2"); case 3: printf ("3") Default: printf ("4");}} int main () {Function (2); return 0;}
As you can see, the disassembly code of switch is no different from the if statement at this time.
A large table is generated when there are four if statements.
2. When there are four branches in the switch statement, the compiler produces a large table
Steps:
1. Subtract 1 from the incoming number, and then make a comparison. Determine whether the parameter exceeds the maximum constant in the switch statement, that is, whether the parameter goes directly into default or case.
2. If the parameter