CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Threaded View

  1. #7
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: How to read text file, line by line using NASM

    The symptoms you describe may very well indicate stack corruption, which results in the all-time popular undefined behavior. The stack essentially is a system resource and you can't simply use stack memory at will. You may only write to stack memory if you properly allocated it (this includes the PUSH instruction which does sort of an implicit allocation) or has been passed to you by the system or runtime environment for that purpose (this includes parameters your function got passed on the stack which, according to the function's signature, may or may not be allowed to be written to).

    The original code from post #2 is a pure assembly language program and as such may even get away with the modifications you alluded to, in the unlikely (I'm not a *nix expert, so I can't really assess this probability) case that the system doesn't make use of the corrupted stack area while shutting down the program in response to the program's exit syscall. Even then, though, it's still extremely bad style - at least...

    A C/C++ program relies on its runtime system and that, with practically absolute certainty, will attempt to make use of the corrupted stack area once main() returns. Your program may or may not read the file and produce the desired output, but then certainly crash, producing more or less "noise", because the enclosing function call's return address on the stack has been corrupted. (This is based on the assumption that the parts you copied from the original assembly code don't include the exit syscall. If it is icluded, however, technically my notes about the pure assembly language program above would apply. But that would be even much worse style...)
    Last edited by Eri523; July 3rd, 2013 at 03:54 PM.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured