srikanthind
New Member
Could you someone help me, how rectify the error "stack underflow error please"
thank you,
thank you,
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.
and how did you get "return" if no "call" in the first place? even it exists, can you even simulate it in debug mode? i havent heard this "stack underflow" my entire life.
start return
and how did you get "return" if no "call" in the first place? even it exists, can you even simulate it in debug mode? i havent heard this "stack underflow" my entire life.
Its very common on small pics.... They only have a small stack to begin with..
srikanthind!! Post your code......
from my quick googling, its something about calling from the stack itself bypassing the default de-constructor. hence by the time the last call is returned (by the default de-construct) the stack is already depleted. i suspect the IDE is not stack-safe or stack-protected, which i never worked with, so thats why this thread caught my eye.
DELAY5 movlw 0x2D
movwf d1
movlw 0xE7
movwf d2
movlw 0x0B
movwf d3
DELAY_LOOP1
decfsz d1, f
goto $+2
decfsz d2, f
goto $+2
decfsz d3, f
goto DELAY_LOOP1
Return
DELAY2 movlw 0x11
movwf d1
movlw 0x5D
movwf d2
movlw 0x05
movwf d3
DELAY_LOOP2
decfsz d1, f
goto $+2
decfsz d2, f
goto $+2
decfsz d3, f
goto DELAY_LOOP2
;4 cycles
goto $+1
goto $+1
Return
DELAY3 movlw 0x1A
movwf d1
movlw 0x8B
movwf d2
movlw 0x07
movwf d3
DELAY_LOOP3
decfsz d1, f
goto $+2
decfsz d2, f
goto $+2
decfsz d3, f
goto DELAY_LOOP3
;5 cycles
goto $+1
goto $+1
nop
RETURN
VEHICLES BSF GPIO,4 ; LED ON
GOTO DELAY5 ; CALLED FOR 5 SECONDS DELAY
BSF GPIO,1
BCF GPIO,2
GOTO DELAY2 ; CALLED FOR 2 SECONDS DELAY
BSF GPIO,0
BCF GPIO,1
BCF GPIO,4
BSF GPIO,5
GOTO DELAY5
MOVLW B'000011'
MOVWF GPIO ; PART C IN ASSIGNMENT
GOTO DELAY3
;BCF GPIO,3
RETURN
START
BSF STATUS, 5 ; Select Bank 1
MOVLW B'111111'
MOVWF OSCCAL
CLRF ANSEL
MOVLW B'00001000'
MOVWF TRISIO
BCF STATUS,5
;MOVLW B'00010100'
;MOVWF GPIO
CLRF GPIO
MOVLW 07H
MOVWF CMCON
DEFAULT
CLRF GPIO
BSF GPIO,2
;BSF GPIO,4
BTFSC GPIO,3
GOTO VEHICLES
GOTO START
END
You are using a "Return" from a "Goto" instruction for each delay routine. You are effectively attempting to "Pop" the return address from the stack, without having pushed it on to the stack to begin with
The Goto instruction does not "Push" the return address onto the stack. Use a"Call" instruction instead to "Push" the return address onto the stack, then your "Return" from each delay routine should work as you expect.