在IL中看起来像什么? [英] What does an if look like in IL?
本文介绍了在IL中看起来像什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
if 语句在编译成IL时是什么样的?
What does an if
statement look like when it's compiled into IL?
这是一个非常简单的构造C#。 sombody能给我一个更抽象的定义吗?
It's a very simple construct in C#. Can sombody give me a more abstract definition of what it really is?
推荐答案
这里有一些如果
语句以及它们如何转换为IL:
Here are a few if
statements and how they translate to IL:
ldc.i4.s 0x2f var i = 47;
stloc.0
ldloc.0 if (i == 47)
ldc.i4.s 0x2f
bne.un.s L_0012
ldstr "forty-seven!" Console.WriteLine("forty-seven!");
call Console::WriteLine
L_0012:
ldloc.0 if (i > 0)
ldc.i4.0
ble.s L_0020
ldstr "greater than zero!" Console.WriteLine("greater than zero!");
call Console::WriteLine
L_0020:
ldloc.0 bool b = (i != 0);
ldc.i4.0
ceq
ldc.i4.0
ceq
stloc.1
ldloc.1 if (b)
brfalse.s L_0035
ldstr "boolean true!" Console.WriteLine("boolean true!");
call Console::WriteLine
L_0035:
ret
有一点需要注意:IL指令总是相反。 如果(i> 0)
转换为有效意味着如果 i< = 0
,则跳过的主体,如果
阻止。
One thing to note here: The IL instructions are always the "opposite". if (i > 0)
translates to something that effectively means "if i <= 0
, then jump over the body of the if
block".
这篇关于在IL中看起来像什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文