-
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