Hello, World
The "Hello, World!" example provided in this document comes in five different versions to accommodate various architectures and operating systems. Each version is tailored to the specific requirements and system calls of the target environment. The versions include:
AArch64 Assembly for macOS: This version uses the AArch64 architecture and macOS-specific system calls.
AArch64 Assembly for Linux: This version is designed for the AArch64 architecture on Linux, utilizing Linux system calls.
x86 Assembly for Linux: This version targets the x86 architecture on Linux, using the appropriate system calls for this environment.
x86-64 Assembly for Linux: This version is for the x86-64 architecture on Linux, with system calls suited for 64-bit systems.
x86-64 Assembly for Windows: This version is written for the x86-64 architecture on Windows, leveraging the Windows API for system calls.
Each version demonstrates how to write and run a simple "Hello, World!" program in assembly language, highlighting the differences in system calls and assembly syntax across various platforms and architectures.
Hello World Example in AArch64 Assembly for macOS
Here is a simple "Hello, World!" program written in AArch64 assembly for macOS:
Instructions to Run the AArch64 Assembly Program in macOS
Save the Code: Save the above code in a file named
hello.s
.Assemble the Code: Use the
as
assembler to convert the assembly code into an object file. Open a terminal and navigate to the directory containinghello.s
. Run the following command:as -arch arm64 -o hello.o hello.sLink the Object File: Use the
ld
linker to create an executable from the object file:ld -o hello hello.o -lSystem -syslibroot `xcrun --sdk macosx --show-sdk-path` -e _startRun the Program: Execute the generated binary:
./helloYou should see the output:
Hello, World!
Summary for AArch64 Assembly on macOS
Save the code in
hello.s
.Assemble with
as -arch arm64 -o hello.o hello.s
.Link with
ld -o hello hello.o -lSystem -syslibroot \
xcrun --sdk macosx --show-sdk-path` -e _start`.Run with
./hello
.
Hello World Example in AArch64 Assembly for Linux
Here is a simple "Hello, World!" program written in AArch64 assembly for Linux:
Instructions to Run the AArch64 Assembly Program in Linux
Save the Code: Save the above code in a file named
hello.s
.Assemble the Code: Use the
as
assembler to convert the assembly code into an object file. Open a terminal and navigate to the directory containinghello.s
. Run the following command:as -o hello.o hello.sLink the Object File: Use the
ld
linker to create an executable from the object file:ld -o hello hello.oRun the Program: Execute the generated binary:
./helloYou should see the output:
Hello, World!
Summary for AArch64 Assembly on Linux
Save the code in
hello.s
.Assemble with
as -o hello.o hello.s
.Link with
ld -o hello hello.o
.Run with
./hello
.
Hello World Example in x86 Assembly for Linux
Here is a simple "Hello, World!" program written in x86 assembly for Linux:
Instructions to Run the x86 Assembly Program in Linux
Save the Code: Save the above code in a file named
hello.asm
.Assemble the Code: Use the
nasm
assembler to convert the assembly code into an object file. Open a terminal and navigate to the directory containinghello.asm
. Run the following command:nasm -f elf32 -o hello.o hello.asmLink the Object File: Use the
ld
linker to create an executable from the object file:ld -m elf_i386 -o hello hello.oRun the Program: Execute the generated binary:
./helloYou should see the output:
Hello, World!
Summary for x86 Assembly on Linux
Save the code in
hello.asm
.Assemble with
nasm -f elf32 -o hello.o hello.asm
.Link with
ld -m elf_i386 -o hello hello.o
.Run with
./hello
.
Hello World Example in x86-64 Assembly for Linux
Here is a simple "Hello, World!" program written in x86-64 assembly for Linux:
Instructions to Run the x86-64 Assembly Program in Linux
Save the Code: Save the above code in a file named
hello.asm
.Assemble the Code: Use the
nasm
assembler to convert the assembly code into an object file. Open a terminal and navigate to the directory containinghello.asm
. Run the following command:nasm -f elf64 -o hello.o hello.asmLink the Object File: Use the
ld
linker to create an executable from the object file:ld -o hello hello.oRun the Program: Execute the generated binary:
./helloYou should see the output:
Hello, World!
Summary for x86-64 Assembly on Linux
Save the code in
hello.asm
.Assemble with
nasm -f elf64 -o hello.o hello.asm
.Link with
ld -o hello hello.o
.Run with
./hello
.
Hello World Example in x86-64 Assembly for Windows
Here is a simple "Hello, World!" program written in x86-64 assembly for Windows using the Windows API:
Instructions to Run the x86-64 Assembly Program in Windows
Save the Code: Save the above code in a file named
hello.asm
.Assemble the Code: Use the
nasm
assembler to convert the assembly code into an object file. Open a terminal and navigate to the directory containinghello.asm
. Run the following command:nasm -f win64 -o hello.obj hello.asmLink the Object File: Use a linker like
GoLink
to create an executable from the object file:golink /entry main /console hello.obj kernel32.dllRun the Program: Execute the generated binary:
hello.exeYou should see the output:
Hello, World!
Summary for x86-64 Assembly on Windows
Save the code in
hello.asm
.Assemble with
nasm -f win64 -o hello.obj hello.asm
.Link with
golink /entry main /console hello.obj kernel32.dll
.Run with
hello.exe
.