Menu
Coddy logo textTech

Printing Two Strings

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

You already know how to print one string. But what if you want to print two separate strings? For example, "Hello " and then "World!"?

You simply call the write syscall twice — once for each string.

How it works:

; First print
mov rax, 1
mov rdi, 1
mov rsi, firstMsg
mov rdx, firstLen
syscall

; Second print
mov rax, 1
mov rdi, 1
mov rsi, secondMsg
mov rdx, secondLen
syscall

Example:

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

    second db 'World!', 0x0a
    secondLen equ $-second

section .text
    global _start

_start:
    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

    mov rax, 60
    mov rdi, 0
    syscall

Output:

Hello World!

Why print two strings instead of one?

ReasonExample
ReusabilityPrint the same greeting with different names
FlexibilityPrint different messages based on conditions
OrganizationKeep different messages separate in memory

You can print as many strings as you want:

Just repeat the write syscall for each string.

challenge icon

Challenge

You are given two strings: partOne with value 'Good' and partTwo with value 'bye'. Both already have a newline at the end.

Write the code to print partOne and then partTwo so that the output shows:

Good

bye

The data section and exit syscall are already provided. You only need to write the two write syscalls.

Try it yourself

section .data
    partOne db 'Good', 0x0a
    partOneLen equ $-partOne
    partTwo db 'bye', 0x0a
    partTwoLen equ $-partTwo

section .text
    global _start

_start:
    ; TODO: Print partOne using write syscall
    ; TODO: Print partTwo using write 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