0Pricing
Assembly Language & x86 Low-Level Systems Programming · บทเรียน

โปรแกรมแอสเซมบลีแรกของคุณ

ตั้งค่าสภาพแวดล้อมการพัฒนา แล้วเขียน ประกอบ เชื่อมโยง และเรียกใช้โปรแกรม 'Hello, World!' อย่างง่ายในแอสเซมบลี x86

โปรแกรมแอสเซมบลีแรกของคุณ เป็นบทเรียน Assembly Language & x86 Low-Level Systems Programming ฟรีบน CoddyKit นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Assembly Language & x86 Low-Level Systems Programming และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Assembly Language & x86 Low-Level Systems Programming มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

Your First Assembly Program

Time to go hands-on: you will set up the tools, write a "Hello, World!" in assembly, and turn it into a runnable executable. This is the fun part.

Get Ready: Assembler & Linker

You need two tools: an assembler (we use NASM) to make an object file, and a linker (LD) to turn that into a runnable program.

Anatomy of an Assembly Program

An assembly program splits into sections. .data holds initialized data like strings; .text holds your instructions, starting at _start.

Storing "Hello, World!"

Store the message in .data. The db directive defines bytes; we add a newline (0xA) and compute the length right after.

section .data
    msg db 'Hello, World!', 0xA
    len equ $ - msg

System Calls: Printing Text

To print, ask the OS via a system call. On Linux that is sys_write (number 1): you pass the output, the address, and the byte count.

section .text
    global _start

_start:
    ; sys_write (syscall number 1)
    mov rax, 1         ; syscall number for sys_write
    mov rdi, 1         ; file descriptor 1 (stdout)
    mov rsi, msg       ; address of the string to write
    mov rdx, len       ; number of bytes to write
    syscall            ; execute the system call

Ending Our Program (Syscall)

When done, the program must tell the OS to stop with a second syscall: sys_exit (number 60), passing an exit status — 0 means success.

    ; sys_exit (syscall number 60)
    mov rax, 60        ; syscall number for sys_exit
    mov rdi, 0         ; exit status 0 (success)
    syscall            ; execute the system call

Your First Full Program!

Here is the full "Hello, World!" — save it as hello.asm. The .data section holds the message, .text prints it and exits.

section .data
    msg db 'Hello, World!', 0xA
    len equ $ - msg

section .text
    global _start

_start:
    ; sys_write (syscall number 1)
    mov rax, 1         ; syscall number for sys_write
    mov rdi, 1         ; file descriptor 1 (stdout)
    mov rsi, msg       ; address of the string to write
    mov rdx, len       ; number of bytes to write
    syscall            ; execute the system call

    ; sys_exit (syscall number 60)
    mov rax, 60        ; syscall number for sys_exit
    mov rdi, 0         ; exit status 0 (success)
    syscall            ; execute the system call

From Assembly to Object File

First, assemble: nasm -f elf64 turns hello.asm into the object file hello.o — machine code, but not yet an executable.

nasm -f elf64 hello.asm -o hello.o

Creating the Executable

The object file isn't runnable yet. The linker (ld) wires up the _start entry point and produces the final executable.

ld hello.o -o hello

Execute and See the Output!

Now run it with ./hello. "Hello, World!" prints to your console — congratulations, you just ran your first x86 assembly program!

./hello

Quick Check: Process Steps

You've seen the full process to create an executable from assembly code. What is the correct order of steps?

Recap: Your First Assembly Program

You ran the full workflow: define data, call sys_write and sys_exit, then assemble, link, and execute. Next: registers and data types.

คำถามที่พบบ่อย

บทเรียน “โปรแกรมแอสเซมบลีแรกของคุณ” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “โปรแกรมแอสเซมบลีแรกของคุณ” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Assembly Language & x86 Low-Level Systems Programming ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Assembly Language & x86 Low-Level Systems Programming มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “โปรแกรมแอสเซมบลีแรกของคุณ”

ตั้งค่าสภาพแวดล้อมการพัฒนา แล้วเขียน ประกอบ เชื่อมโยง และเรียกใช้โปรแกรม 'Hello, World!' อย่างง่ายในแอสเซมบลี x86 คุณปฏิบัติ Assembly Language & x86 Low-Level Systems Programming ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Assembly Language & x86 Low-Level Systems Programming หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Assembly Language & x86 Low-Level Systems Programming บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน

บทเรียน “โปรแกรมแอสเซมบลีแรกของคุณ” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Assembly Language & x86 Low-Level Systems Programming นี้ได้ไหม

ได้ บทเรียน Assembly Language & x86 Low-Level Systems Programming ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. ภาษาแอสเซมบลีคืออะไร
  2. พื้นฐานสถาปัตยกรรม x86
  3. โปรแกรมแอสเซมบลีแรกของคุณ
  4. ชุดเครื่องมือประกอบ ลิงก์ และเรียกใช้โปรแกรม
← กลับไปที่ Assembly Language & x86 Low-Level Systems Programming