Menu
Coddy logo textTech

Putting It Together

Part of the Fundamentals section of Coddy's Assembly journey — lesson 39 of 45.

You have learned all four pieces of the write syscall:

RegisterWhat it holdsValue for screen output
raxSyscall number1 (write)
rdiFile descriptor1 (stdout)
rsiBuffer addressAddress of your string
rdxByte countLength of your string

Now it is time to put them all together.

The complete write syscall pattern:

mov rax, 1          ; syscall number for write
mov rdi, 1          ; file descriptor (stdout)
mov rsi, msg        ; address of the string
mov rdx, msgLen     ; number of bytes to print
syscall             ; ask the OS to print

A complete working program:

section .data
    msg db 'Hello, World!', 0x0a
    msgLen equ $ - msg

section .text
    global _start

_start:
    mov rax, 1
    mov rdi, 1
    mov rsi, msg
    mov rdx, msgLen
    syscall

    mov rax, 60
    mov rdi, 0
    syscall

What this program does:

StepWhat happens
1Prints "Hello, World!" to the screen
2Moves to a new line
3Exits cleanly with code 0

The order matters:

You must set up the registers before executing syscall. The order of the mov instructions does not matter as long as all four are set before syscall.

challenge icon

Challenge

Write a complete program that prints the message "Assembly is fun" followed by a newline, then exits cleanly.

The string and its length are already defined. You only need to write the code inside _start:.

Try it yourself

section .data
    msg db 'Assembly is fun', 0x0a
    msgLen equ $ - msg

section .text
    global _start

_start:
    ; TODO: Set up and call the write syscall
    ; Use rax=1, rdi=1, rsi=msg, rdx=msgLen

    ; TODO: Exit cleanly with code 0
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals