Read the IL code (4) and read the il code

Source: Internet
Author: User
Tags mscorlib

Read the IL code (4) and read the il code

This is the last article in The IL series, mainly about Process Control in IL. I believe that the above three articles show that the IL code is not a big problem. Okay. If you don't talk much about it, just give it a simple explanation.

Let's explain it using examples like the previous articles.

The code for converting to IL is as follows:

 

Do you see the red box I drew? This is the key to process control. Next I will explain it in the last sentence. I hope you can try it yourself and take a look.

. Method private hidebysig static voidMain(String [] args) cilmanaged {. entrypoint// Indicates the entry function of the function program.. Maxstack 2// Maximum number of data items that the evaluation stack can accommodate. Locals init ([0] int32Num, [1] boolFlag)// Declare two variables. The first is int type, and the second is bool type.L_0000: nop// No OperationL_0001: ldc. i4.2// Press the value 2 in the form of a 4-byte integer into the evaluation StackL_0002: stloc.0// Bring up the value at the top of the evaluation stack and assign the value to 0th local variables num, which is equal to the C # code of I = 2L_0003: ldloc.0// Press the 0th variables into the evaluation stack, that is, press the variable num into the evaluation stack.L_0004: ldc. i4.0// Press the value 0 in the form of a 4-byte integer into the evaluation StackL_0005: cgt// Execute operations greater than the command, compare num and 0, and store the results at the top of the evaluation stack. 1 indicates true, that is, I> 0 indicates true.L_0007: stloc.1// Pop up the operation result greater than the command from the evaluation stack and assign the value to 1st variables.L_0008: ldloc.1// Press 1st variables into the evaluation stack, that is, the variable flag is pushed into the evaluation stack.L_0009: brfalse. s L_001a// If brfalse is false, null reference, or 0, the control is transferred to the target command. Here, Because I> 0 is true, it is executed in order and you do not have to skip to L_001a.L_000b: nop// No OperationL_000c: ldstr "I \ u4e3a \ u6574 \ u6570"// Press the string "I as an integer" into the evaluation StackL_0011: call void [mscorlib] System. Console: WriteLine (string)// Call the WriteLine method.L_0016: nop L_0017: nop L_0018: br. s L_0027// Unconditionally transfer the control to the target instruction (short format ). Transfer to call the ReadKey method.L_001a: nop L_001b: ldstr "I \ u4e3a \ u8d1f \ u6570"// Press the string "I is negative" into the evaluation StackL_0020: call void [mscorlib] System. Console: WriteLine (string)// Call the WriteLine method.L_0025: nop L_0026: nop L_0027: call valuetype [mscorlib] System. ConsoleKeyInfo [mscorlib] System. Console: ReadKey () L_002c: pop// Clear the evaluation stack contentL_002d: ret

Well, it's complete. Common commands are described. If you encounter a command that you do not understand at ordinary times, you can go here to see (IL command), Ctrl + F, you should know.

In fact, I am also a beginner. If you have any questions, I hope you can raise them and I will make improvements.

Related Article

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.