Created
January 22, 2021 20:06
-
-
Save tuket/b892c59854123f64efc1d36d04ef3f33 to your computer and use it in GitHub Desktop.
Nasm Linux - Print the contents of a file
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 ; "global" means that the symbol can be accessed in other modules. In order to refer to a global symbol from another module, you must use the "extern" keyword | |
| _start: | |
| mov rax, 2 ; syscall: open | |
| mov rdi, str_testFile | |
| mov rsi, 0 ; flags | |
| syscall | |
| mov rdi, rax ; the file descriptor | |
| mov rsi, buffer | |
| mov rdx, 128 | |
| mov rax, 0; syscall: read | |
| syscall | |
| mov rdi, 1 ; stdout | |
| mov rsi, buffer | |
| mov rdx, rax ; the size returned by read | |
| mov rax, 1; syscall: write | |
| syscall | |
| mov rax, 60 ; syscal: exit | |
| mov rdi, 0 ; return code | |
| syscall | |
| str_testFile: db "test.txt", 0 | |
| SECTION .data | |
| buffer: TIMES 128 db 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment