im trying to program in assembler and i need to do something in order to wait for user input key (only enter or space) witout enter, like y/n options. I read about 16h in dos, its a sys_Call similar in linux? i also read about disabling canonization but look too complicated to the curse level thanks
section .bss
buffer resb 1
input resb 1
section .data
lineasConsola dd 3 ; Lineas (sin informacion) mostradas por defecto
lineasPantalla dd 3
lineasTotales dd 0
lineasContador dd 0
section .text
global _start
leerInput:
push ebx
push ecx
mov eax, 3 ; sys_read
mov ebx, 0
mov ecx, input
mov edx, 1
int 80h
pop ecx
pop ebx
ret
leerCaracter:
mov eax,3 ; sys_read
mov ecx,buffer
mov edx,1
int 80h
cmp eax,0 ;eof
je final
imprimirCaracter:
mov eax, 4 ; sys_write
push ebx ; Resguardo el manejador
mov ebx, 1
int 80h
pop ebx
cmp byte[buffer],10 ; Chequeo si llegue a fin de linea
jne leerCaracter
ret
imprimirLineasTotales
push ebx
push ecx
push edx
mov eax, 4
mov ebx, 1
mov ecx, [lineasTotales]
mov edx, 4
int 80h
pop edx
pop ecx
pop ebx
ret
avanzarLinea ; Actualiza los contadores para poder leer una linea mas
push ebx
mov ebx, [lineasConsola]
inc ebx
mov [lineasConsola], ebx
pop ebx
ret
avanzarPantalla ; Actualiza los contadores para poder leer una nueva pantalla
push ebx
mov ebx, [lineasConsola]
add ebx, lineasPantalla
mov [lineasConsola], ebx
pop ebx
ret
_start:
pop ebx ; argc
pop ebx ; argv[0]
pop ebx ; Nombre del archivo
mov eax,5 ; sys_open
mov ecx,0
int 80h
mov ebx,eax ; Muevo el puntero a ebx para leerlo
test eax,eax
js exite ; Se produjo un error al intentar abrir el archivo
leerLinea:
call leerCaracter ;imprimo una linea
push eax ; Llegue al final de la linea, debo aumentar la cantidad de lineas leidas y chequear si llegue al tope de la consola
push ebx
mov eax, [lineasTotales]
mov ebx, [lineasConsola]
inc eax ; Lei una linea
cmp eax, ebx ; Chequeo si complete la pantalla
mov [lineasTotales], eax
pop ebx
pop eax
jl leerLinea ; No llene la consola
;call imprimirLineasTotales ; Imprimir lineas leidas hasta el momento;no funciona
call leerInput
cmp byte[input],'s'
jne seguir ;no presione la barra
call avanzarLinea ; Usuario presiono la barra
jmp leerLinea
seguir:
cmp byte[input], 'e' ; Usuario presiono enter
jne exite ; No es la barar ni salto de linea, se produce un error
call avanzarPantalla
jmp leerLinea
mov ebx, 0 ; salgo sin errores
mov eax, 1 ; sys_exit
int 80h
final:
call imprimirLineasTotales
mov ebx, 0 ; salgo sin errores
mov eax, 1 ; sys_exit
int 80h
exite:
mov ebx, 6 ; If there was an error, save the errno in ebx
mov eax, 1 ; Put the exit syscall number in eax
int 80h ; Bail out