After spending some time programming in C I wanted to explore the world of assembly. Naturally, I went to YouTube and searched for assembly code. I found some excellent resources like, Fireship’s Assembly Language in 100 Seconds.

I decided to install Netwide Assembler (NASM), an assembler for the x86 CPU architecture. I’m on a mac with an intel chip. To install the assembler I used HomeBrew:

brew install nasm

Below is the code for hello world. If interested check out my GitHub repo: assembly_fun with more details on how to get it run.

global    _main               ;entry point for linker
    section   .text           ;text contains logic for program
_main:                          
    mov       rax, 0x02000004 ;system call for write
    mov       rdi, 1          ;file handle 1 is stdout
    mov       rsi, message    ;address of string to output
    mov       rdx, 13         ;length or number of bytes
    syscall                   ;call kernel to do the write
    mov       rax, 0x02000001 ;system call for exit
    xor       rdi, rdi        ;exit code 0
    syscall                   ;call kernel to exit
    section   .data           ;constants
message:  
    db        "Hello, World", 10 

More resources: NSM Tutorial