Hello world assembly on x86 Linux
Save code below as
hello.asm
global _start
section .data
message: db 'hello, world!', 10
section .text
_start:
mov rax, 1 ; system call number should be stored in rax
mov rdi, 1 ; argument #1 in rdi, where to write (description)?
mov rsi, message ; argument #2 in rsi, where does the string start?
mov rdx, 14 ; argument #3 in rdx, how many bytes to write?
syscall ; this instruction invokes a system call
mov rax, 60 ; 'exit' syscall number
xor rdi, rdi
syscall
Now assemble/build the file
nasm -felf64 hello.asm -o hello.o
Link to create executable
ld -o hello hello.o
Run it
u1@v1vm10:~$ ./hello
hello, world!
No comments:
Post a Comment