; fib_64.asm compiles as 64-bit, using 32 bit registers, fewer numbers global main extern printf section .data format: db '%10d', 10, 0 title: db 'fibinachi numbers', 10, 0 section .text main: push rbx ; we have to save this since we use it mov rdi, title ; arg 1 is a pointer xor rax, rax ; no vector registers in use call printf ; 32-bit operands will zero-extend to 64 bits mov ecx, 52 ; ecx will countdown from 52 to 0 xor eax, eax ; eax will hold the current number xor ebx, ebx ; ebx will hold the next number inc ebx ; ebx is originally 1 print: ; We need to call printf, but we are using eax, ebx, and ecx. ; printf may destroy eax and ecx so we will save these before ; the call and restore them afterwards. push rax ; 32-bit stack operands are not encodable push rcx ; in 64-bit mode, so we use the "r" names mov rdi, format ; arg 1 is a pointer mov rsi, rax ; arg 2 is the current number xor eax, eax ; no vector registers in use call printf pop rcx pop rax mov edx, eax ; save the current number mov eax, ebx ; next number is now current add ebx, edx ; get the new next number dec ecx ; count down jnz print ; if not done counting, do some more pop rbx ; restore rbx before returning mov rax, 0 ret