Search code examples
linuxassemblyx86nasmyasm

Extra characters at the end of filenames I create


I am attempting to learn assembler and am having an issue with this tutorial http://www.tutorialspoint.com/assembly_programming/assembly_file_management.htm

it works fine and dandy except for when it writes out the file. Instead of myfile.txt, it is named myfile.txtWelcome to Tutorials PointWritten to file?.

I can't seem to find out why. I took the source off the tutorial and it does the same thing.

Can someone tell me why?


I am using nasm 2.12.02. I have also tried it on yasm 1.2.0 so I am pretty sure it's the assembler code causing it.

I am building and running on OpenSUSE Linux 3.16.7-35-default #1 SMP Sun Feb 7 17:32:21 UTC 2016 (832c776) x86_64 x86_64 x86_64 GNU/Linux


Solution

  • You probably left out a , 0 (zero byte) to terminate the string in the .rodata section where you put the string constants you're using for file names and file data.

    Linux system calls (like open(2)) that take char* args accept zero-terminated C-style strings, instead of accepting a string length.