Search code examples
linuxassemblyx86-64

Can you explain this x86-64 Assembly program


I am currently learning some x86 Assembly and I would like if someone could explain what this program is doing. I know that it is a "Hello World" program, but I don't understand how it is doing it, or what any code means.

.data
.globl greet
greet:
.string "Hello world."

.text
.global main
main:
    pushq   %rbp
    movq    %rsp,       %rbp
    movq    $greet,     %rdi
    call    puts
    movq    $0,         %rax
    leave
    ret


Solution

    • .data this the place were you put headers and defines to use in main:
    • .global greet .global means the label will be the visible to the linker because in main we will use it.
    • greet: the label initializing
    • pushq %rbp: push rbp register onto the stack
    • movq %rsp, %rbp: RBP = RSP
    • movq $greet, %rdi: RDI = address of greet label
    • call puts: api to print string, which looks for a pointer in RDI
    • movq $0, %rax: nop rax(clear data)
    • leave: exit label
    • ret: termination