I created an assembly program that implements biginteger to calculate big fibonacci numbers. The program works and using gdb
I can verify that the numbers are correctly stored in memory.
The problem comes when I want to print the numbers. Normally I would just use printf
but AFAIK it doesn't support numbers bigger than 64-bit. This means that I need to implement the conversion myself. I know that I need to calculate remainders mod 10
but I don't know how to do that for numbers so big.
Code
section .text
global _start
_start: mov eax, 192
xor ebx, ebx
mov ecx, 2048
mov edx, 0x6
mov esi, 0x22
mov edi, -1
xor ebp, ebp
int 0x80 ; allocate memory
lea r8, [eax] ; a
lea r9, [eax+1024] ; b
mov qword [r8], 0x1
mov qword [r9], 0x1
mov rbx, 0x2 ; fib num counter
jmp fib
fib: inc rbx ; num counter++
mov rsi, 0x0 ; addr for int
mov rdx, 128; counter for int
clc ; clear carry flag
add: mov rax, [r8+8*rsi]
adc rax, [r9+8*rsi] ; rax = a + b
mov rcx, [r8+8*rsi]
mov [r9+8*rsi], rcx ; b = a
mov [r8+8*rsi], rax ; a = a + b
inc rsi
dec rdx
jnz add ; repeat for whole bigint
call print
cmp rbx, 100 ; repeat for 100 fib nums
jl fib
jmp exit
print: ; what to do here?
ret
exit: mov eax, 0x1
xor ebx, ebx
int 0x80