Last active
January 3, 2022 21:43
-
-
Save nekodjin/de295ce73182c5d7bf6291d17f671b7f to your computer and use it in GitHub Desktop.
Linux x64 Hello World with NASM
This file contains 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
%define fd_stdin 0 | |
%define fd_stdout 1 | |
%define fd_stderr 2 |
This file contains 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
%macro sysc 1-4 | |
%if %0 == 4 | |
%if %4 == 0 | |
xor rdx, rdx | |
%else | |
mov rdx, %4 | |
%endif | |
%endif | |
%if %0 >= 3 | |
%if %3 == 0 | |
xor rsi, rsi | |
%else | |
mov rsi, %3 | |
%endif | |
%endif | |
%if %0 >= 2 | |
%if %2 == 0 | |
xor rdi, rdi | |
%else | |
mov rdi, %2 | |
%endif | |
%endif | |
%if %1 == 0 | |
xor rax, rax | |
%else | |
mov rax, %1 | |
%endif | |
syscall | |
%endmacro |
This file contains 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
global _start | |
%include "macros.asm" | |
%include "syscalls.asm" | |
%include "fds.asm" | |
segment .data | |
msg db "Hello, world!", 0x0a | |
len equ $ - msg | |
segment .text | |
_start: | |
sysc sys_write, fd_stdout, msg, len | |
sysc sys_exit, 0 |
This file contains 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
%define sys_read 0 | |
%define sys_write 1 | |
; ... | |
%define sys_exit 60 | |
; ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment