Last active
April 29, 2016 15:29
-
-
Save averagesecurityguy/353638d343a6767c2998fad1e656b763 to your computer and use it in GitHub Desktop.
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
Below is a small assembly program that is supposed to create a file with the filename | |
myfile.txt, which is stored in the file_name "variable." The problem is the program | |
actually creates a file called "myfile.txtWelcome to Tutorials PointWritten to file\n". | |
Any ideas why the filename is getting mangled. According to the create call, I need to | |
provide the pointer to the name and the file mode. What I don't understand is why the | |
pointer to the filename is picking up the other strings. | |
; Taken from http://www.tutorialspoint.com/assembly_programming/assembly_file_management.htm | |
section .data | |
file_name db 'myfile.txt' | |
msg db 'Welcome to Tutorials Point' | |
len equ $-msg | |
msg_done db 'Written to file', 0xa | |
len_done equ $-msg_done | |
section .bss | |
fd_out resb 1 | |
fd_in resb 1 | |
info resb 26 | |
section .text | |
global _start | |
_start: | |
;create the file | |
mov eax,8 | |
mov ebx,file_name | |
mov ecx,0777 ;read, write and execute by all | |
int 0x80 ;call kernel | |
; put file descriptor in fd_out | |
mov [fd_out],eax | |
; exit the program | |
mov eax,1 | |
int 0x80 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Needed to end the file_name string with a null byte so it looks like this now.
file_name 'myfile.txt', 0x00