Re: newbie: I/O with nasm



santosh wrote:
James Daughtry wrote:

push name
call _gets
add esp,4


While I realise that assembly programmers are expected to know what
they are doing, nonetheless, keeping in mind the apparent inexperience
of the OP, gets() is a very dangerous function to use. fgets(), while
marginally more complicated to use, is far safer, even for assembly
programmers.

What's the trick to "fgets()"? I tried that, while working up the "read()" version I just posted, and was getting a segfault. I believe "fgets()" wants a "FILE *"... a "stream" instead of a "file descriptor" or "handle", right? I tried zero... I *think* that was my problem. How do I get/use a "FILE *" ("streams[0]"???)?

Another "problem" - I was aware of this one - "printf()" doesn't actually print anything until the buffer is flushed(!). Printing a newline takes care of it, but if I want to print "name: " and let the user type his name on the same line? I guess "fflush()" would do it, but that wants a "FILE *", too!

I actually found the "low level" functions "read()" and "write()" easier to use! They may not be as "portable", though(?)...

Funny, that the "low level" C calls, dos interrupts, Windows APIs, and Linux sys_calls are all inherently "safe", but they went and wrapped 'em in "gets()", which is not. As James observes, it won't do any harm to use it, in this case, but Randy warned me, a long time ago (I think he was talking to me) that "teaching sloppy solutions to beginners" is a Bad Idea...

Actually, I'm kinda hoping Thomas wants it in "pure asm"! :)

Best,
Frank
.



Relevant Pages

  • Re: Which programming Language
    ... The VAX instruction set was designed partly with ... assembly programmers in mind (and also to map closely to FORTRAN ... and DEC always liked orthogonal CISC ...
    (Debian-User)
  • Re: Which programming Language
    ... The VAX instruction set was designed partly with assembly programmers in mind, and the assembler is designed with HLL features. ... To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx with a subject of "unsubscribe". ...
    (Debian-User)
  • Re: newbie: I/O with nasm
    ... James Daughtry wrote: ... While I realise that assembly programmers are expected to know what ... they are doing, nonetheless, keeping in mind the apparent inexperience ...
    (alt.lang.asm)