-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path071.asm
45 lines (37 loc) · 1022 Bytes
/
071.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
format ELF64 executable 9
segment readable writable
result: times 10 db 0 ;empty string for printing the result later
db 10, 0
segment readable executable
entry start
start:
mov eax, 2 ;init a/b to 2/5
mov ebx, 5
get_next:
mov edi, eax ;old a = result
add eax, 3 ;new a = a + numerator to the right
add ebx, 7 ;new b = b + denominator to the right
cmp ebx, 1000000 ;if b >= 1e6 we are finished
jl get_next
finished:
mov eax, edi ;convert result to string, print and exit
mov ebx, 10
mov ecx, 9
convert_result:
xor edx, edx
div ebx
add edx, '0'
mov [result + ecx], dl
dec ecx
test eax, eax
jnz convert_result
print:
mov eax, 4
mov edi, 1
mov esi, result
mov edx, 12
syscall
exit:
mov rax, 1
xor rdi, rdi
syscall