There are a few related questions to this which I've come across, such as Printf with gas assembly and Calling C printf from assembly but I'm hoping this is a bit different.
I have the following program:
.section .data
format:
.ascii "%d\n"
.section .text
.globl _start
_start:
// print "55"
mov $format, %rdi
mov $55, %rsi
mov $0, %eax
call printf # how to link?
// exit
mov $60, %eax
mov $0, %rdi
syscall
Two questions related to this:
- Is it possible to use only
as
(gas) andld
to link this to theprintf
function, using_start
as the entry point? If so, how could that be done? - If not, other than changing
_start
tomain
, what would be thegcc
invocation to run things properly?