-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfloatlib.s
139 lines (96 loc) · 1.86 KB
/
floatlib.s
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
.intel_syntax noprefix
.data
.globl _float_temp
_float_temp:
.float 0.0
.text
.globl _fneg
_fneg:
push ebp
mov ebp,esp
FLD dword ptr [ebp+8]
FCHS
FSTP dword ptr [ebp+8]
mov eax,[ebp+8]
mov esp,ebp
pop ebp
ret
.globl _fadd
_fadd:
push ebp
mov ebp,esp
FLD dword ptr [ebp+8] # a
FLD dword ptr [ebp+12] # b
FADDP st(1),st(0) # st(0)=a+b
FSTP dword ptr [ebp+8] # corrupt a but we don't care
mov eax,[ebp+8] # return value
mov esp,ebp
pop ebp
ret
.globl _fsub
_fsub:
push ebp
mov ebp,esp
FLD dword ptr [ebp+8] # a
FLD dword ptr [ebp+12] # b
FSUBP st(1),st(0) # st(0)=a-b
FSTP dword ptr [ebp+8] # corrupt a but we don't care
mov eax,[ebp+8] # return value
mov esp,ebp
pop ebp
ret
.globl _fimul
_fimul:
push ebp
mov ebp,esp
FLD dword ptr [ebp+8] # a
FLD dword ptr [ebp+12] # b
FMULP st(1),st(0) # st(0)=a*b
FSTP dword ptr [ebp+8] # corrupt a but we don't care
mov eax,[ebp+8] # return value
mov esp,ebp
pop ebp
ret
.globl _fidiv
_fidiv:
push ebp
mov ebp,esp
FLD dword ptr [ebp+8] # a
FLD dword ptr [ebp+12] # b
FDIVP st(1),st(0) # st(0)=a/b
FSTP dword ptr [ebp+8] # corrupt a but we don't care
mov eax,[ebp+8] # return value
mov esp,ebp
pop ebp
ret
.globl _fcmp
_fcmp:
push ebp
mov ebp,esp
FLD dword ptr [ebp+12] # b: st(0)=b
FLD dword ptr [ebp+8] # a: st(0)=a st(1)=b
FCOMIP st(0),st(1)
FSTP st(0) # remove other from stack
mov esp,ebp
pop ebp
ret
.globl _int2float
_int2float:
push ebp
mov ebp,esp
FILD dword ptr [ebp+8]
FSTP dword ptr [ebp+8]
mov eax,[ebp+8]
mov esp,ebp
pop ebp
ret
.globl _float2int
_float2int:
push ebp
mov ebp,esp
FLD dword ptr [ebp+8]
FISTP dword ptr [ebp+8]
mov eax,[ebp+8]
mov esp,ebp
pop ebp
ret