Skip to content

Instantly share code, notes, and snippets.

@lemol
Created March 3, 2012 10:17
Show Gist options
  • Save lemol/1965387 to your computer and use it in GitHub Desktop.
Save lemol/1965387 to your computer and use it in GitHub Desktop.
Fazendo loop com Intermediate Language.
.method public static int32
SumBetween(int32, int32) cil managed
{
.maxstack 2
.locals init (int32, int32)
// uma para o contador, outra para result
ldarg.0
stloc.0 // i = lower
Loop:
ldloc.0
ldarg.1
bgt Done // if (i > higher)
ldloc.0
ldloc.1
add
stloc.1 // result += i
ldloc.0
ldc.i4.1
add
stloc.0 // i++
br.s Loop
Done:
ldloc.1
ret // return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment