'if' block in IL

I think that maybe I am missing something important, but I cannot figure out how to build a conditional statement in IL with a dynamic method. I used to just mess around a bit, but I need to extend the code now.

Is there some kind of documentation somewhere that I didn't find (other than the CLI documentation), or does anyone have some sample code? That would be fantastic.

Greetings

+3
source share
2 answers

Depending on your exact code, different branch instructions are your friend.

Here

if(memory[pointer] > 0) goto IL_0002;

in IL:

IL_001f:  ldsfld     uint8[] BFHelloWorldCSharp.Program::memory
IL_0024:  ldsfld     int16 BFHelloWorldCSharp.Program::pointer
IL_0029:  ldelem.u1
IL_002a:  ldc.i4.0
IL_002b:  bgt      IL_0002

Basically, you push the values ​​you want to compare onto the stack, and then call bgt to go where you need to.

OpCodes Class IL, brtrue/brfalse beq.

if #, ILDASM Reflector IL.

+4

:

, :

var skipProperty = il.DefineLabel();

:

il.Emit(OpCodes.Brtrue, skipProperty);

, , (, if):

il.MarkLabel(skipProperty);

, ( , , "", , ). OpCodes.Brtrue , ( Michael

+1

Source: https://habr.com/ru/post/1742927/


All Articles