I'm using a 64 bits Linux system, and I'm trying to use NASM to build a program that asks the user for input, and then prints it. Afterwards, the user can choose to do the same again, or exit.
My issue is that the variable 'text', which is used to store the user's input, is not reset at the end of each execution, so something like this happens:
User enters text the 1st time: Helloooooooooooooooooooooooooooooo
Output: Helloooooooooooooooooooooooooooooo
User enters text the 2nd time: Boom!
Output: Boom! oooooooooooooooooooooooooooo
Part of the "Helloooooo" from the first execution is showing up, and I don't know how to prevent that from happening.
I'd appreciate any help, as I'm just starting to learn about this.
Thanks
This is what I've done:
section .data
prompt db "Type your text here.", 0h
retry db "Wanna try again? If yes, enter y. If not, enter anything else to close the program", 0h
section .bss
text resb 255
choice resb 2
section .text
global _start
_start:
mov rax, 1 ;Just asking the user to enter input
mov rdi, 1
mov rsi, prompt
mov rdx, 21
syscall
mov rax, 0 ;Getting input and saving it on var text
mov rdi, 0
mov rsi, text
mov rdx, 255
syscall
mov rax, 1 ;Printing the user input
mov rdi, 1
mov rsi, text
mov rdx, 255
syscall
mov rax, 1 ;Asking if user wants to try again
mov rdi, 1
mov rsi, retry
mov rdx, 83
syscall
mov rax, 0 ;Getting input and saving it on var choice
mov rdi, 0
mov rsi, choice
mov rdx, 2
syscall
mov r8b, [choice] ;If choice is different from y, go to end and close the program. Otherwhise, go back to start.
cmp byte r8b, 'y'
jne end
jmp _start
end:
mov rax, 60
mov rdi, 0
syscall