I have been trying to call printf from x64 asm, but it prints garbage Here is the code:
;print all fib numbers from 0 until 100
global main
extern printf
;printf notes
;mov al 0 is neccesary
;rdi: format string
;rsi, rdx, r8... args
section .text
main:
mov r8, 0 ;counter
mov r9, 0 ;nth value
mov r10, 1;n + 1 value
mov al, 0
Loop:
mov rsi, r9
mov rdx, r10
mov rdi, format_str
call printf
mov r11, r10
add r10, r9
mov r9, r11
inc r8
cmp r8, 100
jl Loop
mov rax, 60
mov rdi, 0
syscall
section .rodata
format_str: db "%3d: %30d\\n", 0
Note the mov al
. If it is inside the loop, the program prints garbage. But if it is outside the loop, then the program segfaults.
I compile with gcc and I simply want it to output as it would if it were called from c