1

Is there a way to disable and enable the display of terminal input within an assembly program?

I am writing a command line program in nasm where user input it periodically read from the terminal (which I want to be displayed) and the program sleeps for certain lengths of time. During that time (unlike what I've found in the Windows command line) the user is still able to type in the terminal. I want to hide that text.

Here's a program that asks for a prompt and waits between certain message:

section .text
   global _start

_start:
   
   mov edx,lhello
   mov ecx,mhello
   mov ebx,1
   mov eax,4    ; sys_write
   int 0x80
   
   mov dword[sleep_sec],1
   mov dword[sleep_usec],0
   mov ecx,0
   mov ebx,sleep
   mov eax,162  ; sys_nanosleep
   int 0x80
   
   mov edx,lwrite
   mov ecx,mwrite
   mov ebx,1
   mov eax,4    ; sys_write
   int 0x80
   
   mov edx,99
   mov ecx,usergift
   mov ebx,0
   mov eax,3    ; sys_read
   int 0x80
   
   mov edx,lsleep
   mov ecx,msleep
   mov ebx,1
   mov eax,4    ; sys_write
   int 0x80
   
   mov dword[sleep_sec],2
   mov dword[sleep_usec],0
   mov ecx,0
   mov ebx,sleep
   mov eax,162  ; sys_nanosleep
   int 0x80
   
   mov edx,ldone
   mov ecx,mdone
   mov ebx,1
   mov eax,4    ; sys_write
   int 0x80
   
   mov eax,1    ; sys_exit
   int 0x80 ; the end!
   
   
section .bss
usergift resb 99

section .data
sleep:
   sleep_sec  dd 0
   sleep_usec dd 0

mhello db 'hello-',0xA
lhello equ $ - mhello

mwrite db 'give me something:'
lwrite equ $ - mwrite

msleep db 'wait for 2 seconds...',0xA
lsleep equ $ - msleep

mdone db 'thank you.',0xA
ldone equ $ - mdone

gives the following output when love is inputted by the user when prompted-

hello-
give me something:love
wait for 2 seconds...
thank you.

but the user is also able to write outside of the prompt-

hello-
ha!give me something:love
wait for 2 seconds...
lies!thank you.
Octopus
  • 21
  • 3
  • 1
    Yes. See [How to stop echo in terminal using c?](https://stackoverflow.com/q/59922972/547981) You will probably also want to drain the input. – Jester Jan 22 '21 at 21:57
  • [How do i read single character input from keyboard using nasm (assembly) under ubuntu?](https://stackoverflow.com/q/3305005) has an answer using 32-bit int 0x80 system calls. (In 64-bit mode, so the program is actually *better* if ported to 32-bit mode where int 0x80 is appropriate.) Anyway, it disables echo as well as canonical mode. If you want canonical without echo, you can just choose which flags to unset; that answer actually defines separate `echo_off` and `canonical_off` functions. – Peter Cordes Jan 22 '21 at 22:30
  • Ah, thank you for pointing me towards that question! And I am already draining the input in the program I'm actually working on, the above was just an small example I put together that more clearly outlined the problem I was asking about. – Octopus Jan 22 '21 at 22:40

0 Answers0