Content deleted Content added
→Assembly language: Intel syntax is much easier to read |
|||
Line 49:
fib:
mov rax, rdi ; put the argument into %eax
test
je .return_from_fib ; yes - return 0, which is already in %eax
cmp
jbe .return_1_from_fib ; yes (i.e., it's 1 or 2) - return 1
mov rcx, rdi ; no - put it in
mov rdx, 1 ; the previous number in the sequence, which starts out as 1
mov rsi, 1 ; the number before that, which also starts out as 1
Line 59:
lea rax, [rsi + rdx] ; put the sum of the previous two numbers into %eax
cmp rcx, 2 ; is the counter 2?
je .return_from_fib ; yes -
mov rsi, rdx ; make the previous number the number before the previous one
dec
mov rdx, rax ; make the current number the previous number
jmp .fib_loop ; keep going
|