I'm trying to write a function in x86 NASM assembly which reverses order of characters in a string passed as argument. I tried implementing it using stack but ended up getting error message   

`*** stack smashing detected ***: <unknown> terminated`   

`Aborted (core dumped)`  

Code below:

```
section .text
global reverse
reverse:
        push ebp                ; epilogue
        mov ebp, esp
        mov eax, [ebp+8]
        xor ecx, ecx            ; ecx = 0
        push ebx                ; saved register
push_eax:
        mov edx, [eax]          ; edx = char at eax
        test edx, edx
        jz inc_eax              ; if edx == 0, move eax pointer back and pop eax
        push edx
        inc eax         
        inc ecx                 ; counter + 1
        jmp push_eax
inc_eax:
        sub eax, ecx            ; move eax back to beginning of string
        mov ebx, ecx            ; to move eax back at the end of function                         
pop_eax:      
        test ecx, ecx           ; loop counter == 0
        jz end  
        pop edx                 
        mov [eax], edx          ; char at eax = edx
        inc eax                 ; eax++
        dec ecx                 ; ecx--
        jmp pop_eax
end:
        sub eax, ebx
        pop ebx                 ; saved register
        mov esp, ebp
        pop ebp
        ret

```

C declaration:

```
extern char* reverse(char*);

```

I've read somewhere that you get this error when trying to for instance write something in an array that is longer than allocated but i don't see how would that function do it?   

Also when instead of using `ebx` at the end I manually move the pointer in `eax` back (string in C of length 9 -> `sub eax, 9`) I get the reversed string at the output followed by 2nd, 3rd and 4th char. (No matter the length of the string I declare in C). So for instance  
`input: "123456789" 
output: "987654321234"`   
but that only happens when I move `eax` manually, using `ebx` like in the code above outputs some trash.