Putting aside the fact for the moment that gets
is a spectacularly unsafe function even when you use it properly (no way to protect against buffer overflow), your immediate problem lies here:
push ecx
call gets
pop ecx
If that ecx
is supposed to be the buffer to read the string into, you haven't set it to anything useful. That's almost certainly why you're getting the memory fault.
The buffer returned from malloc
was placed into eax
, not ecx
. I suspect that's what you want to push as the gets
parameter.
If the memory you allocated is not where you want to put the characters from gets
, you need to initialise ecx
to some other buffer before pushing it.