"C # to IL" chapter III Selection and circulation

Source: Internet
Author: User
Tags mscorlib

-

In IL, a label is a name with a colon (that is,) at the end. It allows us to jump unconditionally from part of the code to another part. We often see this label in the IL code generated by the counter compiler. For example:

IL_0000: ldstr      "hi"
IL_0005: call       void [mscorlib]System.Console::WriteLine(class System.String)
IL_000a: call       void zzz::abc()
IL_000f: ret

The word in front of the colon is the label. In the program given below, we create a label named A2 in function ABC. The directive BR is used to jump to any label in the program at any time.

A.il

.assembly mukhi {}
.class private auto ansi zzz extends System.Object
{
.method public hidebysig static void vijay() il managed
{
.entrypoint
.locals (int32 V_0,class zzz V_1)
newobj instance void zzz::.ctor()
stloc.1
call int32 zzz::abc()
stloc.0
ldloc.0
call void [mscorlib]System.Console::WriteLine(int32)
ret
}
.method private hidebysig static int32 abc() il managed
{
.locals (int32 V_0)
ldc.i4.s   20
br.s a2
ldc.i4.s   30
a2: ret
}
}

Output

20

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.