리눅스/WSL - hello world 어셈블리 코드 x86/x64 (nasm)
WSL에서도 테스트 가능합니다. NASM - The Netwide Assembler를 설치하고,
$ sudo apt install nasm
이렇게 코딩을 추가한 다음,
$ cat hello.asm
; x86 Assembly: Hello World!
; https://youtu.be/HgEGAaYdABA
global _start
section .text:
_start:
    mov eax, 0x4 ; #define __NR_write 4
        ; ssize_t write(int fd, const void *buf, size_t count);
        ;
    mov ebx, 1 ; fd standard console output == 1
    mov ecx, message ; buf
    mov edx, message_length ; count
    int 0x80
    mov eax, 0x1 ; #define __NR_exit 1
        ; void _exit(int status);
    mov ebx, 0 ; status == 0
    int 0x80
section .data:
    message: db "Hello World!", 0x0a
    message_length equ $-message
빌드하면 결과를 확인할 수 있습니다.
$ nasm -f elf32 -o hello.o hello.asm
$ ld -m elf_i386 -o hello hello.o
$ ./hello
Hello World!
동일한 역할의 코드를 x64로 하면 ABI가 달라진다는 점만 고려하면 기본은 같습니다.
// LINUX SYSTEM CALL TABLE FOR X86 64
// https://blog.rchapman.org/posts/Linux_System_Call_Table_for_x86_64/
$ cat app.asm
section .data
    message: db "Hello World!", 0x0a
    message_length equ $-message
section .text
global _start
_start:
    mov rax, 1 ; sys_write
    mov rdi, 1 ; stdout
    mov rsi, message ; buf
    mov rdx, message_length ; count
    syscall
    mov rax, 60 ; sys_exit
    mov rdi, 0 ; error code 0
    syscall
실행도 잘 되고. ^^
$ nasm -f elf64 -o app.o app.asm
$ ld app.o -o app
$ ./app
Hello World!
그나저나, WSL로 인해 개발 환경이 정말 많이 편해졌습니다. ^^
[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]