Skip to content

Instantly share code, notes, and snippets.

@averagesecurityguy
Last active April 29, 2016 15:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save averagesecurityguy/353638d343a6767c2998fad1e656b763 to your computer and use it in GitHub Desktop.
Save averagesecurityguy/353638d343a6767c2998fad1e656b763 to your computer and use it in GitHub Desktop.
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
@averagesecurityguy
Copy link
Author

Needed to end the file_name string with a null byte so it looks like this now.

file_name 'myfile.txt', 0x00

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment