Last active
June 1, 2021 01:11
-
-
Save DavidSouther/da017423f8fc008df6669ab29ac92d7e to your computer and use it in GitHub Desktop.
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
public class fact2 { | |
public static int factorial(int x) { | |
if (x==0) return 1; | |
else return x * factorial (x-1); | |
} | |
public static void main() { | |
int i, gobble; | |
i = 0; | |
WriteLine ("TCCL recursive factorial test"); | |
while ( i < 15) { | |
gobble = factorial (i); | |
WriteLine (gobble); | |
i = i + 1; | |
} | |
} | |
} |
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 extern mscorlib {} | |
.assembly fact2 { } | |
.method static int32 factorial(int32) | |
{ | |
.maxstack 32 | |
.locals init () | |
ldarg.1 | |
ldc.i4.s 0 | |
ceq | |
brfalse.s _if_false_label_0 | |
ldc.i4.s 1 | |
br.s _if_end_label_1 | |
_if_false_label_0: | |
ldarg.0 | |
ldarg.0 | |
ldc.i4.s 1 | |
sub | |
call int32 factorial(int32) | |
mul | |
_if_end_label_1: | |
ret | |
} | |
.method static void main() | |
{ | |
.entrypoint | |
.maxstack 32 | |
.locals init (int32, int32) | |
ldc.i4.s 0 | |
stloc.0 | |
ldstr "TCCL recursive factorial test" | |
call void [mscorlib]System.Console::WriteLine(string) | |
_loop_start_2: | |
ldloc.1 | |
ldc.i4.s 15 | |
clt | |
brfalse.s _loop_end_3 | |
ldloc.0 | |
call int32 factorial(int32) | |
stloc.1 | |
ldloc.1 | |
call void [mscorlib]System.Console::WriteLine(int32) | |
ldloc.0 | |
ldc.i4.s 1 | |
add | |
stloc.0 | |
br.s _loop_start_2 | |
_loop_end_3: | |
ret | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment