Marko Škorić
Marko Škorić

Reputation: 157

How to call fprintf() function in assembly code?

I have a task to write a prime numbers in text file, but I know how to convert a integer to string, and string to integer, but I think that is just a huge work, then I remember that I have a function fprintf that can help me, but I do not know why I getting a segmentation fault, maybe my arguments are not so good, can you help me? I appreciate that.

section .data
content db '%d',10,0
mod db 'w',0
fail db 'Marko.txt',0

section .text
extern printf,fopen,fclose,fprintf
global main
main:
push rbp
mov rbp,rsp
push rdi
push rsi
push rbx
mov rdx,0

mov rdi,fail
mov rsi,mod
call fopen

push rax
mov rsi,rax
mov rdi,content
mov rdx,5
call fprintf

pop rdi
close fclose

pop rbx
pop rsi
pop rdi
mov rsp,rbp
pop rbp
ret

Upvotes: 2

Views: 2132

Answers (1)

prl
prl

Reputation: 12435

The first parameter to fprintf is the FILE.

Upvotes: 2

Related Questions