Dubai, UAE
Offline
Edison Member
Karma: 20
Posts: 1637
|
 |
« on: June 17, 2012, 09:18:12 am » |
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
Brattain Member
Karma: 299
Posts: 26031
Solder is electric glue
|
 |
« Reply #1 on: June 17, 2012, 09:27:38 am » |
do you just find out through unexpected behavior ? That's the one.
|
|
|
|
|
Logged
|
|
|
|
|
Dubai, UAE
Offline
Edison Member
Karma: 20
Posts: 1637
|
 |
« Reply #2 on: June 17, 2012, 09:48:23 am » |
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
Brattain Member
Karma: 143
Posts: 19380
I don't think you connected the grounds, Dave.
|
 |
« Reply #3 on: June 17, 2012, 09:55:32 am » |
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? 
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Dubai, UAE
Offline
Edison Member
Karma: 20
Posts: 1637
|
 |
« Reply #4 on: June 17, 2012, 09:59:50 am » |
You mean some sort of mechanism that pushes the machine's current state and registers onto the stack? Now that you mention it - 
|
|
|
|
|
Logged
|
|
|
|
|
Australia
Offline
Newbie
Karma: 0
Posts: 17
Arduino rocks
|
 |
« Reply #5 on: June 21, 2012, 05:17:49 am » |
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
Shannon Member
Karma: 226
Posts: 14110
Lua rocks!
|
 |
« Reply #6 on: June 21, 2012, 05:26:21 am » |
You mean some sort of mechanism that pushes the machine's current state and registers onto the stack?  Very amusing.  The stack that is no more?
|
|
|
|
|
Logged
|
|
|
|
|
UK
Offline
Edison Member
Karma: 51
Posts: 2477
What a host of balls she had seen: gaity, the brass buttons...
|
 |
« Reply #7 on: June 21, 2012, 05:27:08 am » |
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
Brattain Member
Karma: 143
Posts: 19380
I don't think you connected the grounds, Dave.
|
 |
« Reply #8 on: June 21, 2012, 05:35:03 am » |
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
Shannon Member
Karma: 226
Posts: 14110
Lua rocks!
|
 |
« Reply #9 on: June 21, 2012, 05:40:11 am » |
How is a stack overflow visible in a project ?
The Blue Screen Of Death. Oh, wait. There isn't a screen.
|
|
|
|
|
Logged
|
|
|
|
|
UK
Offline
Edison Member
Karma: 51
Posts: 2477
What a host of balls she had seen: gaity, the brass buttons...
|
 |
« Reply #10 on: June 21, 2012, 05:47:10 am » |
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 
|
|
|
|
|
Logged
|
|
|
|
|
Dubai, UAE
Offline
Edison Member
Karma: 20
Posts: 1637
|
 |
« Reply #11 on: June 21, 2012, 06:08:11 am » |
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
Brattain Member
Karma: 143
Posts: 19380
I don't think you connected the grounds, Dave.
|
 |
« Reply #12 on: June 21, 2012, 06:28:18 am » |
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
Faraday Member
Karma: 42
Posts: 5248
CMiYC
|
 |
« Reply #13 on: June 21, 2012, 01:38:10 pm » |
Just out of interest - I am not near an AVR now, what does it do for divide by zero ?
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: Int: 65535 Float: 0.00
|
|
|
|
|
Logged
|
|
|
|
|
Manchester (England England)
Offline
Brattain Member
Karma: 299
Posts: 26031
Solder is electric glue
|
 |
« Reply #14 on: June 22, 2012, 02:17:38 am » |
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
|
|
|
|
|
|