assembly - ASM x86_64 Hello world program -
i new asm, , i'm trying create basic hello world program, using function :
section .text global main print_msg: push rbp mov rbp, rsp mov rax, 1 mov rdi, 1 mov rsi, buffer ;to change mov rdx, buffersize ;to change syscall mov rsp, rbp pop rbp ret main: mov rdi, buffer mov rsi, buffersize call print_msg mov rax, 60 mov rdi, 0 syscall section .rodata buffer: db 'hello, world !', 0x0a buffersize: equ $-buffer
this code work, because directly copied buffer in rsi , buffersize in rdx, in "print_msg" function, want copy received arguements in these 2 registers, saw :
mov rsi, [rsp + 8] mov rdx, [rsp + 12]
but doesn't work here.
x86-64 uses registers pass arguments, code illustrates:
mov rdi, buffer mov rsi, buffersize call print_msg
if loaded rdi
, rsi
arguments, why expect them on stack in called function? call
doesn't registers, , puts return address on stack. thus, 2 arguments still happily in rdi
, rsi
. mov
them correct place:
mov rdx, rsi mov rsi, rdi mov rax, 1 mov rdi, 1 syscall
Comments
Post a Comment