stack overflow problem

Thread Starter

siangwei

Joined Jan 5, 2011
6
Hi all

I am new in assembly language..
my project is about IC functional test which test TTL74

the problem occur when i runing simulation on proteus and MPLAB SIM..

before i replace the G_OR function with its full test coding..all work fine..after i replace the full coding of OR gate..this problem occur!

i was busy finding the CALL and RETURN instruction but i cant find any wrong there..PLEASE HELP..

thank you all

attachment is the code and proteus circuit file
 

Attachments

Last edited:

Markd77

Joined Sep 7, 2009
2,806
You are getting problems because the code is over 2Kbytes in size - calls stop working because of the quoted reason:

To find the problem you just look at the error:
CORE-E0001: Stack over flow error occurred from instruction at 0x00001f

and the line 1F in the disassembly listing:
001D 3001 MOVLW 0x1 92: MOVLW B'00000001'
001E 0086 MOVWF 0x6 93: MOVWF PORTB
001F 2006 CALL 0x6 94: CALL DELAY5
0020 1788 BSF 0x8, 0x7 95: BSF PORTD,7
0021 200F CALL 0xf 96: CALL DELAY150
0022 1388 BCF 0x8, 0x7 97: BCF PORTD,7
You can then see that address 0x06 is not where the call is intended to go.
(It will still say 0x06 after you have made the below change but changing PCLATH fixes the problem).

You can either change all the calls in the program as suggested below or optimise to reduce the code size below 2K.


From AN556 downloadable from microchip.com
SECTION 1
CALL and GOTO Instructions
When executing a CALL or GOTO, the low 11-bits are
loaded directly from the instruction opcode. The high
2-bits are loaded from bits 3 and 4 of the PCLATH reg-
ister. It is a good practice to pre-load PCLATH with the
high byte of the routine’s address before executing the
routine. This can be done as follows:
EXAMPLE 2:
.
.
movlw HIGH Table ;load high 8-bit
movwf PCLATH ;address of Table into PCLATH
call Routine ;execute Call instruction


.
.
Note:
If the program memory size is less than
2K-words, then the above precaution is
not necessary.
 
Last edited:

Thread Starter

siangwei

Joined Jan 5, 2011
6
Thanks your reply Markd77.

it is imposible for me reduce my code below 2k..somemore i havent need to add in USART code.

"SECTION 1
CALL and GOTO Instructions
When executing a CALL or GOTO, the low 11-bits are
loaded directly from the instruction opcode. The high
2-bits are loaded from bits 3 and 4 of the PCLATH reg-
ister. It is a good practice to pre-load PCLATH with the
high byte of the routine’s address before executing the
routine. This can be done as follows:
EXAMPLE 2:
.
.
movlw HIGH Table ;load high 8-bit
movwf PCLATH ;address of Table into PCLATH
call Routine ;execute Call instruction
SECTION 1
CALL and GOTO Instructions
When executing a CALL or GOTO, the low 11-bits are
loaded directly from the instruction opcode. The high
2-bits are loaded from bits 3 and 4 of the PCLATH reg-
ister. It is a good practice to pre-load PCLATH with the
high byte of the routine’s address before executing the
routine. This can be done as follows:
EXAMPLE 2:
.
.
movlw HIGH Table ;load high 8-bit
movwf PCLATH ;address of Table into PCLATH
call Routine ;execute Call instruction
SECTION 1
CALL and GOTO Instructions
When executing a CALL or GOTO, the low 11-bits are
loaded directly from the instruction opcode. The high
2-bits are loaded from bits 3 and 4 of the PCLATH reg-
ister. It is a good practice to pre-load PCLATH with the
high byte of the routine’s address before executing the
routine. This can be done as follows:
EXAMPLE 2:
.
.
movlw HIGH Table ;load high 8-bit
movwf PCLATH ;address of Table into PCLATH
call Routine ;execute Call instruction
"
i dont get what it mean..can future explain it?
thanks..
 

Markd77

Joined Sep 7, 2009
2,806
This explains it in a different way, maybe it makes more sense.

I can see quite a few optimizations that could reduce your code size, for example there are a lot of these:

TOLCD
CALL DELAY5
BSF PORTD,7
CALL DELAY150
BCF PORTD,7
They could all be reduced to 1 call, which would save over 700 instructions.


<ed> Also have a look at this, all the text to send is stored in the EEPROM and is sent using the message subroutine. It makes changes to the messages very easy and saves a lot of program memory.
It has some USART code in which might be of use, but could need some tweaking for the different PIC model.
http://forum.allaboutcircuits.com/showthread.php?t=40875
<ed>


 

Attachments

Last edited:

Thread Starter

siangwei

Joined Jan 5, 2011
6
From the file an225, i do not get it how its work and why should use this method..it mention about page1 and page2..how can we know whether the cide should put in page1 or page2??
Then the pclath will contain 2bits of call and goto instruction..isnt important??
 

Markd77

Joined Sep 7, 2009
2,806
I'm not sure I can explain it any better than the datasheet, maybe someone else can. You start off in page 0 and you can't call anything in the other pages without changing PCLATH yourself.
The safest way is to change every call and goto to this format:

movlw HIGH Table ;load high 8-bit
movwf PCLATH ;address of Table into PCLATH
call Table ;execute Call instruction


You've got plenty of space so I'd recommend doing it this way.

There are ways of avoiding doing this to every single call and goto but it makes the code harder to maintain and debug and requires more understanding.
 

Thread Starter

siangwei

Joined Jan 5, 2011
6
thanks markd77 idea..can i ask..what is that "Table" for? inside the table what should i write? till now i still cant get how its work..thx for your helpful..
 

Markd77

Joined Sep 7, 2009
2,806
"Table" is just an example.

Here's a bit of your code:
Rich (BB code):
            GOTO        G_EROR_B 
            MOVLW        A'6' 
            CALL        LCD_DISP 
G_EROR_B
My (and Microchip's) recommendation would be to replace that with:
Rich (BB code):
            movlw HIGH G_EROR_B
            movwf PCLATH
            GOTO        G_EROR_B 
            movlw HIGH LCD_DISP
            movwf PCLATH
            MOVLW        A'6' 
            CALL        LCD_DISP 
G_EROR_B
Notice the placement of the second part in bold so that "W" contains the correct value.

I'd still recommend optimising the code first as it will save work on this conversion and might avoid it altogether if you can keep the code under 2K. The 700 instruction saving I suggested earlier would make a good start.
 

Thread Starter

siangwei

Joined Jan 5, 2011
6
I finally get what you mean..thanks for your patience explaination..

isnt for every CALL and GOTO..i need to add this 2 instruction:

movlw HIGH xxx
movwf PCLATH
???
 

Thread Starter

siangwei

Joined Jan 5, 2011
6
hi markd77
i already try to add in the two instruction before all CALL and GOTO..
but the overflow problem still occur..isnt the code is over 2k??
of that can you please explain to me how to make the code in to 2nd pages? and how to call the subroutine in page 2nd page? thounsand thanks for your kindly help
 
Top