Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
FizzBuzz in IL
.assembly extern mscorlib {}
.assembly fizzbuzz {}
.method static void Main() cil managed {
.entrypoint
.maxstack 2
.locals init (int32 i, int32 n)
ldc.i4 1
ldstr "fizzbuzz max>"
call void [mscorlib]System.Console::Write(string)
stloc i
call string [mscorlib]System.Console::ReadLine()
call int32 [mscorlib]System.Int32::Parse(string)
stloc n
LOOP:
ldloc i
ldloc n
bgt LOOPEND
ldloc i
ldc.i4 15
rem
brfalse FIZZBUZZ
ldloc i
ldc.i4 5
rem
brfalse BUZZ
ldloc i
ldc.i4 3
rem
brfalse FIZZ
OTHER:
ldloc i
box int32
br PRINT
FIZZBUZZ:
ldstr "FIZZBUZZ"
br PRINT
BUZZ:
ldstr "BUZZ"
br PRINT
FIZZ:
ldstr "FIZZ"
br PRINT
PRINT:
call void [mscorlib]System.Console::WriteLine(object)
ldloc i
ldc.i4.1
add
stloc i
br LOOP
LOOPEND:
ret
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment