Menu
Coddy logo textTech

Buffer Address (rsi)

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

In the write syscall, after telling the OS where to send the output (file descriptor in rdi), you need to tell it what to print. You do this by passing the address of the string in memory.

The register for the buffer address is rsi.

What is a buffer?

A buffer is simply a block of memory that holds data. In our case, the buffer is the string we want to print.

Why address, not the value itself?

The write syscall needs to know where the string starts in memory. It will read bytes from that address until it reaches the length you specify in rdx. You do not send the actual characters to the syscall — you send their location.

Example:

section .data
    msg db 'Hello', 0x0a

section .text
    mov rsi, msg        ; rsi holds the address of msg

What <strong>msg</strong> really is:

msg is a label. The assembler replaces it with a number — the memory address where the string 'Hello' is stored. When you write mov rsi, msg, you are putting that address number into rsi.

What happens if you forget the address?

If you do not set rsi, the register contains whatever garbage was there before. The OS will try to read from a random memory address, which will likely cause a segmentation fault (crash).

Complete example with write syscall:

section .data
    msg db 'Hello', 0x0a
    len equ $ - msg

section .text
    mov rax, 1          ; write syscall
    mov rdi, 1          ; stdout
    mov rsi, msg        ; address of string
    mov rdx, len        ; number of bytes
    syscall
challenge icon

Challenge

You are given a string called greeting with the value 'Hi' followed by a newline. Write the line of code that loads the address of greeting into rsi.

Only write the mov instruction for rsi.

Try it yourself

section .text
    global _start

_start:
    %include "solution.asm"
    
    mov rax, 1
    mov rdi, 1
    ; rsi already has the address (from student's code)
    mov rdx, greetingLen
    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