-
-
Save AnatolyShirykalov/cf948a9548ee59d5d28e8016c58c5877 to your computer and use it in GitHub Desktop.
NASM x86_64 open file and write 'Hello world'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
section .text | |
global _start ;must be declared for linker (ld) | |
_start: ;tell linker entry point | |
mov rdi, filename | |
mov rsi, 0102o ;O_CREAT, man open | |
mov rdx, 0666o ;umode_t | |
mov rax, 2 | |
syscall | |
mov [fd], rax | |
mov rdx, len ;message length | |
mov rsi, msg ;message to write | |
mov rdi, [fd] ;file descriptor | |
mov rax, 1 ;system call number (sys_write) | |
syscall ;call kernel | |
mov rdi, [fd] | |
mov rax, 3 ;sys_close | |
syscall | |
mov rax, 60 ;system call number (sys_exit) | |
mov rdi, 0 ;do not return error code | |
syscall ;call kernel | |
section .data | |
msg db 'Hello, world', 0xa | |
len equ $ - msg | |
filename db 'test.txt', 0 | |
lenfilename equ $ - filename | |
fd dq 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment