Pages: [1] 2   Go Down
Author Topic: Stack overflow  (Read 1310 times)
0 Members and 1 Guest are viewing this topic.
Dubai, UAE
Offline Offline
Edison Member
*
Karma: 21
Posts: 1670
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: 514
Posts: 31554
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: 21
Posts: 1670
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
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24464
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." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Dubai, UAE
Offline Offline
Edison Member
*
Karma: 21
Posts: 1670
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: 18
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
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 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
Faraday Member
**
Karma: 92
Posts: 3969
Where is your SSCCE?!?!
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

Why not visit my eBay shop? http://stores.ebay.co.uk/Majenko-Technologies
Replacement for the Arduino IDE: UECIDE - Proper serial terminal, graphing facilities, plugins, overhauled internals.
Java isn't bad in itself, but it has enabled morons to write programs.

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24464
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." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 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
Faraday Member
**
Karma: 92
Posts: 3969
Where is your SSCCE?!?!
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

Why not visit my eBay shop? http://stores.ebay.co.uk/Majenko-Technologies
Replacement for the Arduino IDE: UECIDE - Proper serial terminal, graphing facilities, plugins, overhauled internals.
Java isn't bad in itself, but it has enabled morons to write programs.

Dubai, UAE
Offline Offline
Edison Member
*
Karma: 21
Posts: 1670
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
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24464
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." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Austin, TX
Online Online
Faraday Member
**
Karma: 64
Posts: 6055
Baldengineer
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

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 514
Posts: 31554
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
Jump to: