-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproblem2.asm
40 lines (29 loc) · 946 Bytes
/
problem2.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
;
; Problem 2
;
; Each new term in the Fibonacci sequence is generated by adding the previous
; two terms. By starting with 1 and 2, the first 10 terms will be:
;
; 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
;
; By considering the terms in the Fibonacci sequence whose values do not exceed
; four million, find the sum of the even-valued terms.
;
section .text
global _start
_start:
mov r8, 1 ; initial number
mov r9, 1 ; initial number
.loop
xor ebx, ebx ; zero out ebx for later
bt r8, 0 ; if bit 1 is set, it's an odd number
cmovnc rbx, r8 ; copy number to add if
; setc bl
add r10, rbx ; add the even number or zero
xadd r8, r9 ; xchg and add
cmp r8, 0x3d0900 ; see if we're less than 4,000,000
jl .loop
.done
mov eax, 1 ; syscall for exit
mov ebx, 0 ; exit with status zeo
int 80h ; syscall