Menu
Coddy logo textTech

Newline Matters

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

You have been adding 0x0a (newline) at the end of your strings. But what happens if you forget it?

Without newline:

The text prints, but the cursor stays on the same line. Any future output will appear right next to it.

Example without newline:

section .data
    first db 'Hello'
    firstLen equ $ - first
    second db 'World'
    secondLen equ $ - second

section .text
    mov rax, 1
    mov rdi, 1
    mov rsi, first
    mov rdx, firstLen
    syscall

    mov rax, 1
    mov rdi, 1
    mov rsi, second
    mov rdx, secondLen
    syscall

Output:

HelloWorld

No space. No newline. Everything is stuck together.

With newline:

section .data
    first db 'Hello', 0x0a
    firstLen equ $ - first
    second db 'World', 0x0a
    secondLen equ $ - second

Output:

Hello World

Each string prints on its own line.

What newline does:

CharacterASCIIEffect
0x0a10Moves cursor to the beginning of the next line

Common newline mistakes:

MistakeResult
No newline at allText runs together on one line
Newline only at the end of last stringPrevious strings run together, last one goes to next line
Newline in the middle of a stringLine breaks in unexpected places

The safe rule:

Always add 0x0a at the end of every string you want on its own line.

challenge icon

Challenge

You are given three strings without newlines. Your task is to print them so they appear on three separate lines.

The strings are:

StringValue
word1'Apple'
word2'Banana'
word3'Cherry'

Requirements:

  • Define each string with a newline (0x0a) at the end
  • Calculate the length of each string automatically
  • Print all three strings using the write syscall
  • Exit cleanly with code 0

Try it yourself

section .data
    ; TODO: Define word1 with 'Apple' and newline
    ; TODO: Define word2 with 'Banana' and newline
    ; TODO: Define word3 with 'Cherry' and newline
    ; TODO: Calculate lengths for each string

section .text
    global _start

_start:
    ; TODO: Print word1
    ; TODO: Print word2
    ; TODO: Print word3

    ; TODO: Exit cleanlysection .data
    word1 db 'Apple', 0x0a
    word1Len equ $ - word1
    word2 db 'Banana', 0x0a
    word2Len equ $ - word2
    word3 db 'Cherry', 0x0a
    word3Len equ $ - word3

section .text
    global _start

_start:
    mov rax, 1
    mov rdi, 1
    mov rsi, word1
    mov rdx, word1Len
    syscall

    mov rax, 1
    mov rdi, 1
    mov rsi, word2
    mov rdx, word2Len
    syscall

    mov rax, 1
    mov rdi, 1
    mov rsi, word3
    mov rdx, word3Len
    syscall

    mov rax, 60
    mov rdi, 0
    syscall
quiz iconTest yourself

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

All lessons in Fundamentals