-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSoroushpoor-asha-610397170-minDiffFp.asm
247 lines (208 loc) · 3.86 KB
/
Soroushpoor-asha-610397170-minDiffFp.asm
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
extern printf
extern scanf
extern fflush
%include "in_out.asm"
%include "sys-equal.asm"
section .data
ErrAloc db 'Error in allocation',0xA, 0
ErrFree db 'Error in freeing',0xA, 0
min dq 100000000.0
inpfmt db '%lf',0
fmts db '%lf',NL,0
fmto db "%lf %lf", 0
section .bss
len resq 1
arr resq 1000
first resq 1
second resq 1
temp resq 1
section .text
global main
; memalloc:;size should be in rsi return address in rax
; mov rax, sys_mmap
; mov rsi, mem_size
; mov rdx, PROT_READ | PROT_WRITE
; mov r10, MAP_ANONYMOUS | MAP_PRIVATE
; syscall
; cmp rax, -1
; jg memAlocEnd
; call writeNum
; mov rsi, ErrAloc
; call printString
; memAlocEnd:
; ret
; Pmalloc: ;(int64 size) -> int64 address
; enter 0, 0
; push rsi
; push r10
; mov rax, sys_mmap
; mov rsi, [P_FUNC_PARAM_INDEX]
; mov rdx, PROT_READ | PROT_WRITE
; mov r10, MAP_ANONYMOUS | MAP_PRIVATE
; syscall
; cmp rax, -1
; jg PmallocEnd
; mov rsi, ErrAloc
; call printString
; PmallocEnd:
; pop r10
; pop rsi
; leave
; ret 8
; memfree:;address should be in r11 and size in rsi
; mov rax, sys_mumap
; ; mov rsi, mem_size
; mov rdi, r11
; syscall
; cmp rax, -1
; jg memFreeEnd
; mov rsi, ErrFree
; call printString
; memFreeEnd:
; ret
flush:
push rdi
xor rdi, rdi
call fflush
pop rdi
ret
printt:
; fst qword[temp]
push r9
push r8
push rbx
push rax
push rbp
mov rdi,fmts
movq xmm0,qword [min]
mov rax,1
call printf
pop rbp
pop rax
pop rbx
pop r8
pop r9
ret
updatemin:
;r8 is i
;r9 is j
;rbx is base
fld qword[rbx+r8*8]
; call printt
fld qword[rbx+r9*8]
; call printt
fsubp
; call printt
ftst
fnstsw ax
and ax,0100011100000000B
cmp ax,0000000000000000B
je updateminnochs
fchs
updateminnochs:
fstp qword[temp]
fld qword[min]
fld qword[temp]
; call printt
fcompp
fnstsw ax
and ax, 0x4500
; call writeNum
; call newLine
cmp ax, 0x0100
je updatemindo
jmp updateminExt
updatemindo:
mov [first],r8
mov [second],r9
fld qword[temp]
fstp qword [min]
updateminExt:
ret
main:
finit
call readNum
mov [len], rax
mov rcx,[len]
mov rbx,arr
inputLoop:
push rcx;counter
push rbx;address
push rbp
mov rdi, inpfmt;address of input format
mov rsi, rbx;first argument pinter to location of float
xor rax,rax
call scanf
pop rbp
pop rbx
pop rcx
add rbx, 8;next address
loop inputLoop
;initialize
mov qword[first],0
mov qword[second],1
mov rbx,arr
fld qword [rbx]
fld qword [rbx+8]
fsubp
ftst
fnstsw ax
and ax,0100011100000000B
cmp ax,0000000000000000B
je aftersignchange
fchs
aftersignchange:
fst qword[min]
mov r8,0
for1:
mov r9,r8
inc r9
mov rax, [len]
cmp r9, rax
jge for2ext
for2:
; mov rax,r8
; call writeNum
; mov al,' '
; call putc
; mov rax, r9
; call writeNum
; call newLine
mov rbx,arr
call updatemin
mov rax, [len]
inc r9
cmp r9, rax
jl for2
for2ext:
inc r8
mov rax, [len]
cmp r8, rax
jl for1
; mov rax,[first]
; call writeNum
; call newLine
; mov rax,[second]
; call writeNum
; call newLine
; push rbp
; mov rdi,fmts
; movq xmm0,qword [min]
; mov rax,1
; call printf
; pop rbp
mov r8,[first]
mov r9,[second]
mov rbx,arr
push rbp
mov rdi,fmto
movq xmm0,qword [rbx+r8*8]
movq xmm1,qword [rbx+r9*8]
mov rax,2
call printf
pop rbp
call flush
Exit:
mov rax, sys_exit
xor rdi, rdi
syscall