Reading notes: baby steps in x86 assembly

04 Aug 2022

Reading notes about assembly programming for future use.

Hello world

Tools

References

Code

section .text
        global _start   ; must be declared for linker (ld) (like main function)

_start:                 ; entry point
        mov edx, len    ; message length
        mov ecx, msg    ; message to write
        mov ebx, 1      ; file descriptor (stdout)
        mov eax, 4      ; system call number (sys_write)
        int 0x80        ; call kernel

        mov eax, 1      ; sys cam number (sys_exit)
        int 0x80        ; call kernel

section .data
        msg db 'Hello world|', 0xa
        len equ $ - msg    

Compile

 
    nasm -f elf64 -g -F dwarf  <source.s> 
    # -g -F dwarf : for debugging purposes
 
    ld <source.o> -o <exec_nane>
    # eg. ld hw.o -o exec

Debug

    gdb <exec_name> -tui
    # optional: -tui (text user interface)

Useful gdb commands:

Hello world

    def foo
        puts 'foo'
    end