Loading...
Pages: [1] 2   Go Down
Author Topic: Stack overflow  (Read 787 times)
0 Members and 1 Guest are viewing this topic.
Dubai, UAE
Offline Offline
Edison Member
*
Karma: 20
Posts: 1637
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

How is a stack overflow visible in a project ? Does it reset the Arduino or is there a specific interrupt that gets triggered or do you just find out through unexpected behavior ?

Thanks

Duane B

rcarduino.blogspot.com
Logged


Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 299
Posts: 26031
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
do you just find out through unexpected behavior ?
That's the one.
Logged

Dubai, UAE
Offline Offline
Edison Member
*
Karma: 20
Posts: 1637
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks,

I have just made a few changes that should be good for 30 or 40 bytes, I am running on an 1K ATMega8 and the project is behaving as if a global variable is being overwritten with zero after a period.

Duane.

Logged


Global Moderator
UK
Online Online
Brattain Member
*****
Karma: 143
Posts: 19380
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
or is there a specific interrupt that gets triggered
You mean some sort of mechanism that pushes the machine's current state and registers onto the stack?   smiley-wink
Logged

Pete, it's a fool looks for logic in the chambers of the human heart.

Dubai, UAE
Offline Offline
Edison Member
*
Karma: 20
Posts: 1637
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
You mean some sort of mechanism that pushes the machine's current state and registers onto the stack?

Now that you mention it - smiley-red

Logged


Australia
Offline Offline
Newbie
*
Karma: 0
Posts: 17
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You might be able to see it occur if you run the hex file in a simulator like AVR Studio 4, I show it happening here:

Logged

Global Moderator
Melbourne, Australia
Offline Offline
Shannon Member
*****
Karma: 226
Posts: 14110
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You mean some sort of mechanism that pushes the machine's current state and registers onto the stack?   smiley-wink

Very amusing. smiley

The stack that is no more?
Logged


UK
Offline Offline
Edison Member
*
Karma: 51
Posts: 2477
What a host of balls she had seen: gaity, the brass buttons...
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Some more advanced microcontrollers do have a system for handling this.  It's just like an interrupt, but it's called an "exception".   They are more critical than interrupts, and you aren't always expected to be able to return from it.  They are usually linked to such events as "address error", or "divide by 0" and other such critical events.

Not something the low-end Atmel chips do I'm afraid.
Logged


Global Moderator
UK
Online Online
Brattain Member
*****
Karma: 143
Posts: 19380
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My favourite was the 68000 double bus error.
A single bus error caused the processor to jump via a vector when an area of memory that wasn't mapped was accessed.
A double bus error occurred when the bus error vector pointed to a region of memory that wasn't mapped!
Logged

Pete, it's a fool looks for logic in the chambers of the human heart.

Global Moderator
Melbourne, Australia
Offline Offline
Shannon Member
*****
Karma: 226
Posts: 14110
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

How is a stack overflow visible in a project ?

The Blue Screen Of Death.

Oh, wait. There isn't a screen.
Logged


UK
Offline Offline
Edison Member
*
Karma: 51
Posts: 2477
What a host of balls she had seen: gaity, the brass buttons...
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

My favourite was the 68000 double bus error.
A single bus error caused the processor to jump via a vector when an area of memory that wasn't mapped was accessed.
A double bus error occurred when the bus error vector pointed to a region of memory that wasn't mapped!
I'm sure my guru meditated on that problem many a time smiley
Logged


Dubai, UAE
Offline Offline
Edison Member
*
Karma: 20
Posts: 1637
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Just out of interest - I am not near an AVR now, what does it do for divide by zero ?

Duane B
Logged


Global Moderator
UK
Online Online
Brattain Member
*****
Karma: 143
Posts: 19380
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Divide by zero?
Nothing at all.
Carries on, regardless.
Logged

Pete, it's a fool looks for logic in the chambers of the human heart.

Austin, TX
Offline Offline
Faraday Member
**
Karma: 42
Posts: 5248
CMiYC
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Just out of interest - I am not near an AVR now, what does it do for divide by zero ?

Code:
void setup() {
Serial.begin(9600);
unsigned int numerator = 47;
unsigned int denominator = 0;
unsigned int result = numerator / denominator;

Serial.print("Int: ");
Serial.println(result);
float floatNumerator = 47.0;
float floatDenominator = 0.0;
float floatResult = floatNumerator / floatDenominator;
Serial.print("Float: ");
Serial.println(floatResult);
}

Resulted in:
Code:
Int: 65535
Float: 0.00
Logged

www.cmiyc.com - A guide to being an Enginerd

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 299
Posts: 26031
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Divide by zero is a concept that we have, to the computer it is just another operation. Sometimes we build the "this is a bad thing" concept into the processor, other times into the software, but the processor dosn't cair.
Logged

Pages: [1] 2   Go Up
Print
 
Jump to: