Athena
Athena

Reputation: 543

Change end of line character for user input in assembly

I am writing a calculator program in nasm and I would like to read user input until user enters =. In other words, I don't want the user to press enter for end of input line. Is there any special system call or something for that?

Upvotes: 2

Views: 400

Answers (1)

Peter Cordes
Peter Cordes

Reputation: 364358

Assuming you're talking about Linux or OS X system calls for reading input from a Unix TTY, the normal way is to put the TTY in raw mode with ioctl so you see every character as its typed, no line-editing.

But you can also set the TTY's eol (end of line) character. e.g. from the command line,

stty eol =

You can test it with cat and see that = (as well as newline) submit your buffered text to the kernel so cat sees it and prints it.

Use strace to see what system calls stty uses to do that. It's ioctl(0, TCGETS, { stuf ...}) = 0

(The stty sane and/or reset shell commands will reset your terminal settings back to normal after playing with stuff.)

Upvotes: 2

Related Questions