Error Code 3 when using UART

I have been experimenting with COM port 1 on the UART. I have a PC terminal connected to the PIC through this UART comport 1, (via rs232 chip), and it receives/outputs text fine.

However after about 10 messages received it bombs out with error code 3. It is a simple program where when the word "HELLO" is received from the terminal it runs the hello world function and it works fine but only for around ten times.

I am guessing that it is something to do with the UART buffer maybe???? Any tips would be great - I was experimenting with clearing the variable string buffer etc and this made no difference. I have attached the code below.....

Hello,
you are running out of stack space because the local variables, x and s$ are being created each time they go round the while loop. The solution is to move all of the 'dim' to the top of the function. Also, but this will still work in your version, it is a good idea to use () even if the function does not have any parameters so change set_uart1 to set_uart1()