emperror123
Member level 5
since i have been doing a project i have used up a lot of CALL instruction, and it stack overflowed, how can i prevent this situation if i still continue do that
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
What Kurenai_ryu says is true if you have too many NESTED calls (a call made when you are already in a subroutine). The actual number of calls in the program doesn't matter, what happens when you use the call instruction is the address to return to is saved on the stack. The return instruction goes back to that address and also releases a storage location on the stack again. If you nest too many calls the stack runs out of space and the error occurs. Firstly, check that each of your call instructions has a matching return instruction. If you can debug and watch the stack contents you should see if there is a mismatch. Secondly, if the code is OK and you really have just run out of space, consider using a software stack instead. This lets you use far more nesting but there is a substantial penalty in code size and speed.
Brian.
since i have been doing a project i have used up a lot of CALL instruction, and it stack overflowed, how can i prevent this situation if i still continue do that
org 00
goto START
DELAY1 ;4999993 cycles
movlw 0x2C
movwf d1
movlw 0xE7
movwf d2
movlw 0x0B
movwf d3
decfsz d1, f
goto $+2
decfsz d2, f
goto $+2
decfsz d3, f
goto $-5
;3 cycles
goto $+1
nop
;4 cycles (including call)
return
START CLRF PORTB
CLRF PORTD
CLRF PORTC
BANKSEL TRISA
DELAY1
PAGESEL DELAY1 ; just in case but not clear!!!
movlw 0x2C
movwf d1
movlw 0xE7
movwf d2
movlw 0x0B
movwf d3
decfsz d1, f
goto $+2
decfsz d2, f
goto $+2
decfsz d3, f
goto $-5
;3 cycles
nop
;4 cycles (including call)
return
cblock 0x20
d1
d2
d3
COUNT
endc
DELAY1
movlw .165 ; 0xA5
movwf d1
PLoop0 movlw .41 ;0x29
movwf d2
PLoop1 movlw .147 ;0x93
movwf d3
PLoop2 nop ;clrwdt
nop ;clrwdt
decfsz d3, 1
goto PLoop2
decfsz d2, 1
goto PLoop1
decfsz d1, 1
goto PLoop0
return