T3STY
Full Member level 4
After successfully experimenting with C on the PIC 16F84, I've run into some code weight issues and even some time calibration issues, which made me want to start digging in assembly. I wrote the first straight-trough ASM program, compiled - worked just fine. Now, when I wanted to levelup the experience by working with subroutines I just couldn't get them right.
That might be the dumbest error I've ever made, I'm not sure it's my fault (actually, it's always user/programmer 's fault...) or simulation program's fault (ISIS), but I can't figure out why I'm not able to create any subroutine call. This is the code I'm using:
Compilation in MPLAB succeeds. But when I run the program in ISIS I get this error:
[PIC16 CORE] PC=0x0003. Stack underflow executing RETURN instruction.
Oh, you don't want a return instruction? Then I won't give it to you. I commented the RETURN instruction and, guess what...
[PIC16 CORE] PC=0x0003. Stack overflow executing CALL instruction.
Oh, ok, you don't want CALLs, you don't want RETURNs.. then you mean you don't want subroutines at all, do you?
I tried writing subroutines in many many ways, I even copy-pasted code from websites (which I suppose it's not written by me, and it's working) but still it won't work. It always fails with the RETURN instruction. And this is crazy because when I make a CALL there has to be a RETURN or I'm possibly stuck in the subroutine without returning where I left.
Please, guys, tell me what's the right way to write subroutines in PIC assembly? I've checked out PIC manuals all over the web and as I said, I wasn't able to understand the mistake I'm making. If you could write me a small working example it would be even better.
Thank you!
That might be the dumbest error I've ever made, I'm not sure it's my fault (actually, it's always user/programmer 's fault...) or simulation program's fault (ISIS), but I can't figure out why I'm not able to create any subroutine call. This is the code I'm using:
Code ASM - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 PROCESSOR 16F84A RADIX DEC INCLUDE "P16F84A.INC" __CONFIG 0x3FF1 ORG 0x00 TestRoutine: MOVLW 0xFF MOVWF PORTA RETURN CALL TestRoutine SLEEP END
Compilation in MPLAB succeeds. But when I run the program in ISIS I get this error:
[PIC16 CORE] PC=0x0003. Stack underflow executing RETURN instruction.
Oh, you don't want a return instruction? Then I won't give it to you. I commented the RETURN instruction and, guess what...
[PIC16 CORE] PC=0x0003. Stack overflow executing CALL instruction.
Oh, ok, you don't want CALLs, you don't want RETURNs.. then you mean you don't want subroutines at all, do you?
I tried writing subroutines in many many ways, I even copy-pasted code from websites (which I suppose it's not written by me, and it's working) but still it won't work. It always fails with the RETURN instruction. And this is crazy because when I make a CALL there has to be a RETURN or I'm possibly stuck in the subroutine without returning where I left.
Please, guys, tell me what's the right way to write subroutines in PIC assembly? I've checked out PIC manuals all over the web and as I said, I wasn't able to understand the mistake I'm making. If you could write me a small working example it would be even better.
Thank you!
Last edited: