/
ckfiniteTest.il
108 lines (95 loc) · 1.77 KB
/
ckfiniteTest.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//Tests the ckfinite instruction
//First test on an infinite (finite / 0)
//Second test on NaN (0 / 0)
//Third test sees if value is left on stack if finite
//Both print either PASS or FAIL
//Assumes div works as per specifications
.assembly extern mscorlib{}
.assembly someTest{}
.module someTest
.class private auto ansi someTest
extends [mscorlib]System.Object {
.method public static int32 Main() cil managed {
.entrypoint
.locals (int32 res)
ldc.i4 3
stloc res
//TEST 1 - infinite
.try {
ldc.r8 1
ldc.r8 0
div
ckfinite
ldstr "FAIL"
call void [mscorlib]System.Console::WriteLine(string)
leave test2
}
catch [mscorlib]System.ArithmeticException {
pop
ldstr "PASS"
call void [mscorlib]System.Console::WriteLine(string)
ldloc res
ldc.i4 1
sub
stloc res
leave test2
}
catch [mscorlib]System.Exception {
pop
ldstr "EFAIL"
call void [mscorlib]System.Console::WriteLine(string)
leave test2
}
//TEST 2 - NaN
test2: nop
.try {
ldc.r8 0
ldc.r8 0
div
ckfinite
ldstr "FAIL"
call void [mscorlib]System.Console::WriteLine(string)
leave test3
}
catch [mscorlib]System.ArithmeticException {
ldstr "PASS"
call void [mscorlib]System.Console::WriteLine(string)
ldloc res
ldc.i4 1
sub
stloc res
leave test3
}
catch [mscorlib]System.Exception {
ldstr "FAIL"
call void [mscorlib]System.Console::WriteLine(string)
leave test3
}
//TEST 3
test3: nop
.try {
ldc.r8 3.777
ckfinite
ldc.r8 3.777
bne.un FAIL
ldstr "PASS"
call void [mscorlib]System.Console::WriteLine(string)
ldloc res
ldc.i4 1
sub
stloc res
leave end
FAIL: ldstr "FAIL"
call void [mscorlib]System.Console::WriteLine(string)
leave end
}
catch [mscorlib]System.Exception {
ldstr "FAIL"
call void [mscorlib]System.Console::WriteLine(string)
leave end
}
end:
ldloc res
ret
}
}