# /* factorial function in C0 */ # # int main() { # return factorial(9); # } # # int factorial(int n) { # if (n == 0) return 1; # int tmp = factorial(n-1); # return (n * tmp); # } c0 c0 ff ee # magic 00 01 # version 00 00 # int count 00 00 # string count 00 02 # function count # main(): 00 00 # no arguments 00 00 # no locals 00 06 # 6 bytes (0x06) # main code: Stack: . 10 09 # bipush 9 9 B8 00 01 # invokestatic 1 fact(9) B0 # return . # factorial(n): 00 01 # 1 argument 00 02 # 2 variables: n = V[0], tmp = V[1] 00 1A # 26 bytes (0x1A) # factorial code: Stack: . 15 00 # vload 0 n 10 00 # bipush 0 n, 0 9F 00 13 # if_icmpeq . 15 00 # vload 0 n 10 01 # bipush 1 n, 1 64 # isub n-1 B8 00 01 # invokestatic 1 fact(n-1) 36 01 # vstore 1 . (V[1] = fact(n-1)) 15 00 # vload 0 n 15 01 # vload 1 n, tmp 68 # imul n * tmp B0 # return . # : # . 10 01 # bipush 1 1 B0 # return . 00 00 # no natives