Created
October 27, 2021 12:10
-
-
Save pirrmann/a62b5784acb497a8aa22b0de673054cd to your computer and use it in GitHub Desktop.
IL Fib with tail call
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.assembly ConsoleApp | |
{ | |
} | |
.class public auto ansi abstract sealed beforefieldinit Program | |
extends System.Object | |
{ | |
// Methods | |
.method assembly hidebysig static | |
int32 FibAcc ( | |
int32 a, | |
int32 b, | |
int32 n | |
) cil managed | |
{ | |
.maxstack 8 | |
IL_0000: ldarg.2 | |
IL_0001: brtrue.s IL_0005 | |
IL_0003: ldarg.0 | |
IL_0004: ret | |
IL_0005: ldarg.1 | |
IL_0006: ldarg.0 | |
IL_0007: ldarg.1 | |
IL_0008: add | |
IL_0009: ldarg.2 | |
IL_000a: ldc.i4.1 | |
IL_000b: sub | |
tail. | |
IL_000c: call int32 Program::FibAcc(int32, int32, int32) | |
IL_0011: ret | |
} | |
.method public hidebysig static | |
int32 Fib ( | |
int32 n | |
) cil managed | |
{ | |
.maxstack 8 | |
IL_0000: ldc.i4.0 | |
IL_0001: ldc.i4.1 | |
IL_0002: ldarg.0 | |
IL_0003: call int32 Program::FibAcc(int32, int32, int32) | |
IL_0008: ret | |
} | |
.method public hidebysig static | |
void Main () cil managed | |
{ | |
.entrypoint | |
.maxstack 8 | |
ldc.i4.6 | |
call int32 Program::Fib(int32) | |
call void [System.Console]System.Console::WriteLine(int32) | |
ret | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment