Skip to content

Instantly share code, notes, and snippets.

@kamiyaowl
Created January 16, 2015 14:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kamiyaowl/e4694a15bae77003da90 to your computer and use it in GitHub Desktop.
Save kamiyaowl/e4694a15bae77003da90 to your computer and use it in GitHub Desktop.
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