The smallest Hello world ELF

发布于 2019-10-14  116 次阅读

We use intel format asm to achieve this function:


section .data
	msg db "Hello world!", 0xA
	len equ $ - msg
section .text
global _start
	mov rax, 4
	mov rbx, 1
	mov rcx, msg
	mov rdx, len
	int 0x80
	mov rax, 1
	mov rbx, 0
	int 0x80

compile & link & run

demo$ nasm -f elf64 hello.asm 
demo$ ls
hello.asm  hello.o
demo$ ld -s hello.o -o hello 
demo$ ls
hello  hello.asm  hello.o
demo$ chmod +x hello 
demo$ ./hello
Hello world!