Hello World - Linux 64bit - libc printf version

This is the 64bit version of the famous: "hello, world" program written in assembly language on a Linux system. Instead of using a system call to write the string to stdout, this version make use of libc's printf function.


    
.section .data
	msg: .asciz "Hello, world\n"

.section .text
    .global _start
_start:
	# printf
	pushq %rax		# Push an arbitrary register to the stack to align it.
	mov $msg, %rdi		# The message itself.
	mov $0x0, %rax		# printf is a varargs function, set the number of vector
	call printf		# arguments passed to it - here 0 - and then call printf.
	popq %rax		# Pop the arbitrary register to get it off the stack.

	# exit
	mov $0x0, %rdi
	call exit

Assuming the file is called helloprintf64.s, compile and link it with the following commands:



as -o helloprintf64.o helloprintf64.s
ld -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o helloprintf64 -lc helloprintf64.o