Simulator stack underflow bug

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am simulating an ATmega168 in Studio4.12 SP3 b490 and getting the message:

AVR Simulator:Stack Underflow at 0x08a5

This occurs when I simulate the RET at 0x08a5 the stack pointer moves from 0x04FD to 0x04FF as RAMEND on a ATmega168 is at 0x04FF this is not a stack underflow.

More oddly it depends how the program gets to 0x08a5 by one route it always generates the message by another the message never occurs.

Am I missing something ? Even if its a bug there should be something in the pattern to narrow it down but I can't see it.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Trevor_G wrote:
I am simulating an ATmega168 in Studio4.12 SP3 b490 and getting the message:

AVR Simulator:Stack Underflow at 0x08a5

This occurs when I simulate the RET at 0x08a5 the stack pointer moves from 0x04FD to 0x04FF as RAMEND on a ATmega168 is at 0x04FF this is not a stack underflow.

More oddly it depends how the program gets to 0x08a5 by one route it always generates the message by another the message never occurs.

Am I missing something ? Even if its a bug there should be something in the pattern to narrow it down but I can't see it.

Hi,

it's hard to tell what the problem might be without more information.

- What is the difference between the two paths the program reaches the offending RET instruction? (calls from different places, different entry points into the subroutine, ,,,)?
- Apart from normal calls and interrupts, do you do any explicit stack manipulation (push/pop, changing the stack pointer, etc).
- Do you have any other warnings from the simulator before this occurs?
etc.

If you think you have found a simulator bug, we'd appreciate you send a sample program exhibiting the problem to avrbeta atmel com.

- Roland

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Roland,

I finally found the source of the problem :D
It was buried deep inside 19 source files generating over 8K of code! :!:

But it is really very simple. If you do an ICALL on return the simulator issues a stack underflow .

The code below does it for me every time.

Trevor

start:
	ldi r16, high(RAMEND); Main program start
	out SPH,r16
	ldi r16, low(RAMEND)
	out SPL,r16		; Initialise Stack pointer
main_loop1:
	ldi 	ZL,low(Test)	
	ldi 	ZH,high(Test)	
	icall
	rjmp    main_loop1       	

Test:
	ret