I am new to assembly programming. I am trying to do a simple thing which is read input from the terminal. I want to use fgets to do so. However I am facing a problem when trying to read multiple times.
I have been trying to solve it for a couple days now with no idea why the problem is occuring. I've tried debugging the program, but it crashes outside the code I wrote, so I have no clue what I did wrong.
The thing that makes it even more weird is that if I input less than 7 letters, I can do it as many times as I wish and the program works as I want it to. However the moment I input a 7th letter (or 8th if we count null-terminating char) the program works fine the first time, but on the next call it gives me a "Segmentation fault (core dumped)" error. I know this is an odd problem but I have no clue why it happens.
The following code is a very primative version of what I have but the exact same problem still occurs.
.data
buffer: asciz ""
.text
.global main
main:
call test
call test
call test
.global test
test:
movq $buffer, %rdi #the buffer to save to
movq $10000, %rsi #the number of letters I want
movq stdin, %rdx #where to read from (terminal)
call fgets
Any help is appreciated, Thanks!