-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path002.asm
35 lines (28 loc) · 907 Bytes
/
002.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
section .data
msg db "%d", 10, 0 ;return string for printf (just the result)
section .text
extern printf
global main
main:
xor eax, eax ;result
mov ebx, 1 ;fib (n-1)
mov ecx, 2 ;fib (n)
fib:
test ecx, 1 ;check if number is odd
jnz odd ;if it is, jump to odd
add eax, ecx ;if even, add to result
odd:
xadd ecx, ebx ;exchange ebx and ecx, put the sum in ecx
cmp ecx, 4000000 ;check if we are still under 4 million
jl fib ;if yes, back to fib
print: ;printing routine, differs slightly from OS to OS
push rbp
mov edi, msg
mov esi, eax
call printf
pop rbp
exit: ;exit routine, dito
mov eax, 1
xor edi, edi
syscall
section .note.GNU-stack ;just for gcc