/
Simple3.il
62 lines (62 loc) · 1.49 KB
/
Simple3.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
//----------- Program header
.assembly extern mscorlib { auto }
.assembly OddOrEven { }
.module OddOrEven.exe
//----------- Aliasing
.typedef [mscorlib]System.Console as TTY
.typedef method void TTY::WriteLine(string) as PrintLine
//----------- Class Declaration
.class public Odd.Or.Even {
//------------ Field declaration
.field public static int32 val
//------------ Method declaration
.method public static void check( ) {
.entrypoint
.locals init (int32 Retval)
AskForNumber:
ldstr "Enter a number"
call PrintLine
.try {
// Guarded block begins
call string TTY::ReadLine()
// pop
// ldnull
ldstr "%d"
ldsflda int32 Odd.Or.Even::val
call vararg int32 sscanf(string,string,...,int32*)
stloc.0
leave.s DidntBlowUp
// Guarded block ends
}
catch [mscorlib]System.Exception
{ // Exception handler begins
pop
ldstr "KABOOM!"
call PrintLine
leave.s Return
} // Exception handler ends
DidntBlowUp:
ldloc.0
brfalse.s Error
ldsfld int32 Odd.Or.Even::val
ldc.i4.1
and
brfalse.s ItsEven
ldstr "odd!"
br.s PrintAndReturn
ItsEven:
ldstr "even!"
br.s PrintAndReturn
Error:
ldstr "How rude!"
PrintAndReturn:
call PrintLine
ldloc.0
brtrue.s AskForNumber
Return:
ret
} // End of method
} // End of class
//------------ Calling unmanaged code
.method public static pinvokeimpl("msvcrt.dll" cdecl)
vararg int32 sscanf(string,string) { }