/
even-odd.il
70 lines (61 loc) · 1.52 KB
/
even-odd.il
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
.assembly EvenOdd { }
.class EvenOdd
{ .method private static bool IsEven(int32 N) il managed
{ .maxstack 2
ldarg.0 // N
ldc.i4.0
bne.un NonZero
ldc.i4.1
ret
NonZero:
ldarg.0
ldc.i4.1
sub
tail.
call bool EvenOdd::IsOdd(int32)
ret
} // end of method `EvenOdd::IsEven'
.method private static bool IsOdd(int32 N) il managed
{ .maxstack 2
// Demonstrates use of argument names and labels
// Notice that the assembler does not covert these
// automatically to their short versions
ldarg N
ldc.i4.0
bne.un NonZero
ldc.i4.0
ret
NonZero:
ldarg N
ldc.i4.1
sub
tail.
call bool EvenOdd::IsEven(int32)
ret
} // end of method `EvenOdd::IsOdd'
.method public static void Test(int32 N) il managed
{ .maxstack 1
ldarg N
call void [mscorlib]System.Console::Write(int32)
ldstr " is "
call void [mscorlib]System.Console::Write(class System.String)
ldarg N
call bool EvenOdd::IsEven(int32)
brfalse LoadOdd
ldstr "even"
Print:
call void [mscorlib]System.Console::WriteLine(class System.String)
ret
LoadOdd:
ldstr "odd"
br Print
} // end of method `EvenOdd::Test'
} // end of class `EvenOdd'
//Global method
.method public static void main() il managed
{ .entrypoint
.maxstack 1
ldc.i4 10000001
call void EvenOdd::Test(int32)
ret
} // end of global method `main'