Thijser
Thijser

Reputation: 2633

assembly write to file x86

The following code is ment to write foobar in a textfile. named tests.txt located in H. However it does no suchs thing it doesn't give me an error either it just leaves the file in the same state I found it. While decoding it seems %eax is 0 after calling _fopen which looks to me lik

blablaaa: .asciz "foobar /n"
filewritemode: .asciz "a"
filelocation: .asciz "/h/tests.txt"


_main:  

push $filewritemode
push $filelocation
call _fopen


push $blabla
push %eax 
call _fprintf
addl $16,%esp
push $0
call _exit # exit the program

I use gcc to compile this thing in case it matters and have been able to successfully call printf's before. When experimenting with playing sounds I found out that changing the location for the sound into just test.wav worked however this didn't work here could there be something to this? By the way Yes I have tried /H/test.txt H:/test.txt test.txt am I missing something? Or could this maybe be a permission issue?

Upvotes: 0

Views: 1196

Answers (1)

Jester
Jester

Reputation: 58762

You are passing arguments to fprintf reversed too. Come on, pay a little more attention, you have made this mistake once already!

That shouldn't affect return value from fopen, though. That part works for me. Note that some environments require 16 byte alignment of the stack pointer.

By the way, /n is not a line feed, in case you wanted that.

Upvotes: 1

Related Questions