br 無條件跳轉到指定標籤。br.s 為短跳轉(1 字節運算元),功能相同。範例中 br.s a2 使 ldc.i4.s 30 被略過,直接 ret 返回 20。
true/false 編譯為整數 1/0。.cctor 中 ldc.i4.1 stsfld 初始化布爾欄位。brfalse 掃描堆疊頂:1 視為 true(不跳轉),0 視為 false(跳轉)。// C# 代碼
class zzz {
static bool i = true;
public static void Main() {
if (i)
System.Console.WriteLine("hi");
}
}
IL:
.method public hidebysig static void vijay() il managed {
.entrypoint
ldsfld bool zzz::i
brfalse.s IL_0011
ldstr "hi"
call void [mscorlib]System.Console::WriteLine(string)
IL_0011: ret
}
brfalse.s IL_0011 實現「若為假則跳過輸出」。
if 指令,高階 if 全部轉為分支指令。IL_XXXX 由反編譯器生成。