-1

How would I do file io in assembly? And I mean assembly. I hate macros. I'm looking to edit a pre-existing 10 MB file with ASM.

If someone could give me some quick example code on how to do it, that would be appreciated.

Thanks!

0

2 Answers 2

3

All the actual file I/O is going to be handled by the OS, abstracted away by the open()/close()/read()/write()/etc. system calls (or whatever the equivalents are on Windows). So really all your ASM needs to do is call out to these functions (correctly setting up arguments on the stack, etc.), and handling return values.

So if you already know how to use open()/close() etc. in C, and you know how to call a function from ASM, then you're done!

3
  • Thanks. I already figured as much. I'm really just looking for someone providing a quick example ASM code on how to do this.
    – The Roll
    Feb 22, 2011 at 23:49
  • @TheRoll: an example of what? How to call a function? Feb 23, 2011 at 19:28
  • Examples of calling file IO functions, aye.
    – The Roll
    Feb 23, 2011 at 19:44
3

While reading a file certainly should not be your first program if you're learning assembly Here's an example. As long as you're in Windows, you'll need to somehow invoke CreateFile in the win32 API.

The example calls CreateFile using macros, don't let that stop you, you can easily open the nasm include files and look at the assembly behind the macros and copy paste that assembly.

14
  • Isn't Iczelion the one who starts his ASM tutorial by assuming you're familiar with assemblers?
    – The Roll
    Feb 22, 2011 at 23:53
  • Anyway, I'm going for file io because I learn by doing and I prefer to do things that are practical. That's why I'm starting with a basic program to binary edit some stuff for me.
    – The Roll
    Feb 22, 2011 at 23:54
  • I guess I'll stick to compiling from a high level language into ASM and reading that when I want to learn some code. I'm quickly getting the impression SO is the wrong place to be looking for help with assembly - there don't seem to be many, if any, assembly coders here.
    – The Roll
    Feb 22, 2011 at 23:57
  • 4
    @TheRoll: your problem is that you don't know as much as you think you know. You're being told the truth, but are too ignorant to recognize it. Almost nobody uses assembler for file I/O. There is no value in doing so in 99.99 percent of all cases. Feb 23, 2011 at 19:27
  • 1
    @The Roll: It's not so much my opinion, as it is an actual fact. No-one writes assembler nowadays unless they have no choice (i.e. no compiler available), or they need to optimise a hot-spot. Handling file I/O is probably neither of these, so you won't find a great deal of people who've spent any time thinking about file I/O in ASM. What's more, as I said in my answer, this is nothing more than the intersection of file I/O in C and function-calling in ASM. Learn either of those and you're 50% of the way there. Feb 23, 2011 at 21:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.