Created
August 4, 2016 19:30
-
-
Save mmccollow/c9e79eaf0c01385cf1dbfd84cd94f844 to your computer and use it in GitHub Desktop.
Assembly exercise - write "Hello world" to a new file called "test"
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
SECTION .data | |
msg db "Hello world" | |
len equ $ - msg | |
fname db "test", 0 | |
SECTION .text | |
global _start | |
_start: | |
mov rdi, fname ;param1 to open(), file name | |
mov rsi, 101 ;param2 to open(), file mode | |
mov rdx, 0q666 ;param3 to open(), file permissions | |
mov rax, 2 ;open() | |
syscall | |
mov rdi, rax ;put file handle as param1 to write() | |
mov rsi, msg ;param2 to write(), our message | |
mov rdx, len ;param3 to write(), msg length | |
mov rax, 1 ;write() | |
syscall | |
mov rax, 3 ;close(), file handle should already be in rdi | |
syscall | |
mov rax, 60 ;exit() | |
syscall |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment