1 ; fib_64l.asm using 64 bit registers to implement fib.c 2 global main 3 extern printf 4 5 section .data 6 00000000 2531356C640A00 format: db '%15ld', 10, 0 7 00000007 666962696E61636869- title: db 'fibinachi numbers', 10, 0 8 00000010 206E756D626572730A- 9 00000019 00 10 11 section .text 12 main: 13 00000000 55 push rbp ; set up stack 14 00000001 48BF- mov rdi, title ; arg 1 is a pointer 15 00000003 [0700000000000000] 16 0000000B B800000000 mov rax, 0 ; no vector registers in use 17 00000010 E8(00000000) call printf 18 19 00000015 B95F000000 mov rcx, 95 ; rcx will countdown from 52 to 0 20 0000001A B801000000 mov rax, 1 ; rax will hold the current number 21 0000001F BB02000000 mov rbx, 2 ; rbx will hold the next number 22 print: 23 ; We need to call printf, but we are using rax, rbx, and rcx. 24 ; printf may destroy rax and rcx so we will save these before 25 ; the call and restore them afterwards. 26 00000024 50 push rax ; 32-bit stack operands are not encodable 27 00000025 51 push rcx ; in 64-bit mode, so we use the "r" names 28 00000026 48BF- mov rdi, format ; arg 1 is a pointer 29 00000028 [0000000000000000] 30 00000030 4889C6 mov rsi, rax ; arg 2 is the current number 31 00000033 B800000000 mov eax, 0 ; no vector registers in use 32 00000038 E8(00000000) call printf 33 0000003D 59 pop rcx 34 0000003E 58 pop rax 35 0000003F 4889C2 mov rdx, rax ; save the current number 36 00000042 4889D8 mov rax, rbx ; next number is now current 37 00000045 4801D3 add rbx, rdx ; get the new next number 38 00000048 48FFC9 dec rcx ; count down 39 0000004B 75D7 jnz print ; if not done counting, do some more 40 41 0000004D 5D pop rbp ; restore stack 42 0000004E B800000000 mov rax, 0 ; normal exit 43 00000053 C3 ret