Table of Contents

IronForgeCyber

Courses

Resources

Blog

Log In



IronForgeCyber

AboutPrivacyTerms

© 2026 IronForgeCyber. All rights reserved.

  1. courses
  2. asm-101
  3. hello-world
3 min read

Hello, World

Time to write a complete program from nothing. You met every piece in Assembling & Linking and System Calls; this challenge is about putting them together yourself, start to finish.

Problem

Write an assembly program that prints a short message to the screen and then exits cleanly — using only the write and exit system calls, no C library. Assemble it with nasm, link it with ld, and run it.

Hints

New to this? Open one hint at a time before reading the walk-through.

Hint 1
The message is data, not code. Put it in section .data and give it a label so you can refer to its address.
Hint 2
write is syscall number 1. Its three arguments — file descriptor, buffer address, byte count — go in rdi, rsi, rdx. Standard output is file descriptor 1.
Hint 3
Don't count the string by hand. Let the assembler do it: len equ $ - msg sets len to the current address minus the string's start, i.e. its length in bytes.
Hint 4
Finish with syscall 60 (exit), status in rdi. If you skip it, execution runs off the end of your code into whatever bytes follow and crashes.

Walk-through

The program splits into two sections. section .data holds the message, and section .text holds the instructions. The label _start must be marked global because it is the entry point the linker hands to the kernel.

The body is just two system calls. The first is write(1, msg, len): load 1 into rax (the syscall number), 1 into rdi (stdout), the address of the message into rsi, its length into rdx, then syscall. The second is exit(0): 60 into rax, 0 into rdi, and one more syscall. The only trick is the length — rather than hard-coding 14, the equ $ - msg idiom lets the assembler measure the string so the count can never drift out of sync with the text.

Solution

nasm
1section .data
2    msg db "Hello, world!", 10    ; 10 is the newline byte
3    len equ $ - msg               ; assembler computes the length
4

Assemble, link, and run it — then check the exit status:

shell
$ ./hello; echo $?Hello, world!0

The message prints, and the 0 from echo $? is the exit status _start passed to exit — a clean finish, not a crash.

5
section .text
6 global _start
7_start:
8 mov rax, 1 ; syscall 1 = write
9 mov rdi, 1 ; fd 1 = stdout
10 mov rsi, msg ; buffer address
11 mov rdx, len ; byte count
12 syscall
13
14 mov rax, 60 ; syscall 60 = exit
15 xor rdi, rdi ; status 0
16 syscall