Below is a simple "Hello, World!" program written in x86-64 assembly language for Linux. I'll also provide instructions on how to assemble, link, and run it on Fedora Linux.
Save the following code in a file named hello.asm
:
section .data
hello db 'Hello, World!', 0x0A ; 'Hello, World!' followed by a newline (0x0A)
section .text
global _start
_start:
; Write 'Hello, World!' to stdout
mov eax, 1 ; syscall: sys_write
mov edi, 1 ; file descriptor: stdout
lea rsi, [hello] ; address of the string to write
mov edx, 14 ; length of the string (13 characters + 1 newline)
syscall ; invoke the system call
; Exit the program
mov eax, 60 ; syscall: sys_exit
xor edi, edi ; exit code: 0
syscall ; invoke the system call
-
Install the necessary tools (if not already installed): You need
nasm
(Netwide Assembler) andld
(GNU linker). Install them usingdnf
:sudo dnf install nasm binutils
-
Assemble the code: Use
nasm
to assemble thehello.asm
file into an object file:nasm -f elf64 hello.asm -o hello.o
This generates an object file named
hello.o
. -
Link the object file: Use
ld
to link the object file into an executable:ld hello.o -o hello
This creates an executable file named
hello
. -
Run the program: Execute the program using:
./hello
You should see the output:
Hello, World!
.data
section: Contains the stringHello, World!
and a newline character (0x0A
)..text
section: Contains the program's instructions._start
: The entry point of the program.- System calls:
sys_write
(eax = 1): Writes the string to stdout.sys_exit
(eax = 60): Exits the program with a status code of 0.