-
Notifications
You must be signed in to change notification settings - Fork 0
/
06a.asm
126 lines (107 loc) · 1.95 KB
/
06a.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
; nasm -felf64 06a.asm && ld 06a.o && ./a.out
global _start
section .text
ceil:
; ceil(x) = round(x + 0.5 - eps)
mov r10, 1
cvtsi2sd xmm8, r10
mov r11, 2
cvtsi2sd xmm9, r11
divsd xmm8, xmm9
addsd xmm0, xmm8
mov r11, 1000000000
cvtsi2sd xmm9, r11
divsd xmm8, xmm9
subsd xmm0, xmm8
cvtsd2si rax, xmm0
ret
floor:
; floor(x) = round(x - 0.5 + eps)
mov r10, 1
cvtsi2sd xmm8, r10
mov r11, 2
cvtsi2sd xmm9, r11
divsd xmm8, xmm9
subsd xmm0, xmm8
mov r11, 1000000000
cvtsi2sd xmm9, r11
divsd xmm8, xmm9
addsd xmm0, xmm8
cvtsd2si rax, xmm0
ret
solve:
mov r8, [input_time + 8 * rax]
mov r9, [input_dist + 8 * rax]
mov r10, r8
imul r10, r10
mov r11, r9
imul r11, 4
sub r10, r11
cvtsi2sd xmm1, r10
sqrtsd xmm2, xmm1
cvtsi2sd xmm3, r8
addsd xmm3, xmm2
mov r10, 2
cvtsi2sd xmm8, r10
divsd xmm3, xmm8
movsd xmm0, xmm3
call ceil
mov r12, rax
cvtsi2sd xmm3, r8
subsd xmm3, xmm2
mov r10, 2
cvtsi2sd xmm8, r10
divsd xmm3, xmm8
movsd xmm0, xmm3
call floor
mov r13, rax
mov rax, r12
sub rax, r13
sub rax, 1
ret
write_int:
mov r8, buf
add r8, 8 * 20
mov byte [r8], 10
dec r8
mov r9, 2
loop_start: cmp rax, 0
jz loop_end
xor rdx, rdx
mov rbx, 10
div rbx
add rdx, 48
mov byte [r8], dl
dec r8
inc r9
jmp loop_start
loop_end: mov rax, 1
mov rdi, 1
mov rsi, r8
mov rdx, r9
syscall
ret
_start:
mov r15, 1
mov rax, 0
call solve
imul r15, rax
mov rax, 1
call solve
imul r15, rax
mov rax, 2
call solve
imul r15, rax
mov rax, 3
call solve
imul r15, rax
mov rax, r15
call write_int
mov rax, 60
xor rdi, rdi
syscall
section .data
input_time dq 48, 93, 84, 66
input_dist dq 261, 1192, 1019, 1063
section .bss
buf resb 25