-
Notifications
You must be signed in to change notification settings - Fork 0
/
076.asm
55 lines (46 loc) · 1.21 KB
/
076.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
format ELF64 executable 9
segment readable writable
result: times 20 db 0 ;empty string for printing the result later
db 10, 0
p: rd 101
segment readable executable
entry start
start:
mov dword [p], 1 ;set p[0] to 1
xor edi, edi ;init n
sum_outer:
inc edi ;n++
mov esi, edi ;m = n
sum_inner:
push rsi
sub esi, edi ;m - n
mov eax, [p + 4 * esi] ;p[m - n]
pop rsi
add [p + 4 * esi], eax ;p[m] += p[m - 1]
inc esi ;m++
cmp esi, 100 ;end of p?
jle sum_inner ;if not, continue inner loop
cmp edi, 99
jl sum_outer
finished:
mov eax, [p + 400] ;result in p[100]
mov ebx, 10
mov ecx, 19
convert_result:
xor edx, edx
div ebx
add edx, '0'
mov [result + rcx], dl
dec ecx
test eax, eax
jnz convert_result
print:
mov eax, 4
mov edi, 1
mov esi, result
mov edx, 22
syscall
exit:
mov eax, 1
xor edi, edi
syscall