PDA

View Full Version : Stack over flow with IF THEN RETURN ENDIF???



kdoske
- 9th December 2007, 15:36
I was wondering, when I use an IF THEN statement am I allowed to use a return within the statement? Im just not sure how PBP structures an IF THEN in assembly and I am affraid if I use a return statement within an IF THEN it will cause some kind of stack over flow. EXAMPLE:

MAIN:
GOSUB FLAG:
GOTO MAIN:


FLAG:
IF FLAG0 = 0 THEN
C0ON = C0MAIN
FLAG0 = 1
RETURN
ENDIF


Thanks for the help and info

ronjodu
- 9th December 2007, 17:01
Hello kdoske, welcome to the forum. This is an awsome place for help.

As far as your question, I do it in my programs without any problems. I'm quite sure it's OK to do however in your snippett I believe you should have a RETURN after the ENDIF incase your IF FLAG0 = 0 THEN statement doesn't execute, unless there's more after the ENDIF you didn't show.

Hope this helps.

kdoske
- 9th December 2007, 17:19
Wow, thanks so much for the quick reply. I am new to pic basic and I am loving how easy it is. It doesn't take place of all assembly language but its a great tool. So far I am really impressed with its ease of use.

Oh no, there is much more involved in the program. I just copy and pasted that little bit. Once again thanks so much for the info.

Kdoske

mister_e
- 9th December 2007, 17:20
ENDIF is more a compiler directive to tell where the IF-THEN statement block finish. I don't see any problem using it like that... but it might be caused by the Sunday's lack of sleep ;)