Go Down

Topic: sketch limit size (Read 1 time) previous topic - next topic

bocek

I'have taken this error so many times?

Code: [Select]
Binary sketch size: 3414 bytes (of a 14336 byte maximum)

robtillaart

It is not an error, it states that the size of the sketch you made is smaller than the amount of Flash memory available.
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)


Senso


It is not an error, it states that the size of the sketch you made is smaller than the amount of Flash memory available.


mowcius


Graynomad

Quote
how can we fix it?

If you don't compile your program you won't get that message...problem fixed.
Rob Gray aka the GRAYnomad www.robgray.com

davekw7x

#6
Apr 27, 2011, 04:29 pm Last Edit: Apr 27, 2011, 05:50 pm by davekw7x Reason: 1

Quote
how can we fix it?
...don't compile ...


Or...

You could paste the following into setup()  5461 times:
Code: [Select]

   asm("nop"); // Two bytes worth of doing nothing except burning a clock cycle


Then the compiled sketch size will be equal to the maximum.



Regards,

Dave

mowcius

Quote
asm("nop"); // Two bytes worth of doing nothing except burning a clock cycle


Unfortunately it would be more than that wouldn't it? - Have you accounted for all of the other rubbish automatically added in?

davekw7x


...it would be more than that wouldn't it? ...


Well obviously my post was made with sardonic intent, and I haven't actually inserted 5461 no-ops into anything to make the code size larger.

However, since you brought it up:

Ummm---What extra rubbish?

A nop instruction consists of one word of all zeros.  When I put the asm("nop") instruction in a given program, the program ends up with two more bytes in the text section and no other stuff that I can see.

Am I missing something?  I mean, there are certainly some mysterious things (waiting to bite us in the butt) in the demimonde that we call Arduino, but people have been known to use no-ops to give sub-microsecond delays right?  Do we really have to worry about a bunch of extra rubbish?



Regards,

Dave

Onions

Quote
Well obviously my post was made with sardonic intent, and I haven't actually inserted 5461 no-ops into anything to make the code size larger.


I have, and it only took a couple of minutes!  :D :D :D

I copied and pasted 5461 lines of asm("nop");. It gave:

Quote
Binary sketch size: 11368 bytes (of a 30720 byte maximum)


Onions.
My website: http://www.harryrabbit.co.uk/electronics/home.html Up and running now! (Feel free to look round!) :D

davekw7x

#10
Apr 27, 2011, 08:57 pm Last Edit: Apr 27, 2011, 08:59 pm by davekw7x Reason: 1

Binary sketch size: 11368 bytes ...


My sarcastic comment was about inserting no-ops in the setup() function of a given sketch.  What was the sketch size before you pasted in the no-ops?


Regards,

Dave

Onions



Binary sketch size: 11368 bytes ...


My sarcastic comment was about inserting no-ops in the setup() function of a given sketch.  What was the sketch size before you pasted in the no-ops?


Regards,

Dave


It was 450 bytes. The code was:

Code: [Select]
void setup(){

[lots of no-ops]

}

void loop(){}


Without all the no-ops, the basic code compiles to 450 bytes.
On a more serious point, I am very interested as to how the no-ops function works. I have never heared of the asm() function before, and a google search reveals the American Society for Microbiology. What is it meant to do?

Thanks, Onions.
My website: http://www.harryrabbit.co.uk/electronics/home.html Up and running now! (Feel free to look round!) :D

davekw7x

#12
Apr 27, 2011, 09:57 pm Last Edit: Apr 28, 2011, 12:08 am by davekw7x Reason: 1

...
Binary sketch size: 11368 bytes ...It was 450 bytes.


Count again.  I'm betting that you inserted 5459 no-ops, not 5461.  (450 + 2*5459 = 11368)

Since we are being silly, I pasted exactly 5461 no-ops into the setup() function of the Blink example sketch.

Original size was 990 bytes.  With 5461 no-ops, the size is 11912 bytes.  (990 + 2*5461 = 11912)

With an empty sketch like yours, the size went from 428 bytes to 11350 (428 + 2*5461 = 11350)

Note that small differences in absolute code size (428 bytes contrasted with 450)  are undoubtedly due to different compiler versions, but the important thing (if anything in this thread---up to this point---can rightly be called important) is that each no-op increases the sketch size by exactly two bytes, as I previously claimed.  No extra junk that I can see.

Quote from: Onions

On a more serious point, I am very interested as to how the no-ops function works. I have never heared of the asm() function before, and a google search reveals the American Society for Microbiology. What is it meant to do?


The asm() function is not a standard C (or C++) library function.  It is supplied by the compiler/library vendor to allow programmers to insert assembly language instructions in the middle of their C programs.  You can read about it here: avr-libc: Inline Assembler Cookbook

The no-op instruction itself does exactly what its name implies: Does not affect the state of the CPU, i.e. it doesn't change contents of memory or registers or change flags or anything else.  It has to be fetched from memory, like all other instructions, and it takes exactly one clock cycle to fetch the instruction and do nothing else.

What is the asm() function good for?  Well, sometimes people think they are smarter than the compiler and they use asm() stuff to force certain instructions to be executed rather than trust the compiler to create assembly code that is as tight as it can be.  (Sometimes they are even right!)

What is the no-op instruction good for? Well sometimes people need to fine-tune the timing of their programs for various real-time purposes.  For example the SD library uses no-ops in a couple of places to make sure that external setup and hold times are met for certain of the SPI data transfers.  I have used no-ops in assembly language programs where I needed to equalize delay times between different branches of a routine that was generating symmetric waveforms

Stuff like that.


Regards,

Dave

Footnote:
Since the asm() function is not a standard C or C++ library function, its actual syntax requirements may change.  I experimentally determined that the simple form that I showed works for me in this test.  If I were going to use this seriously, I might use the form shown in the avr-libc reference that I gave (which is the form that is used in Sd2Card.cpp in the utility directory of the SD library).

Onions

Thanks davekw7x!

It makes sense now. It is interesting to hear that the no-op actually has a use, and I will remember it for any future codes that need it. That assembly language is complicated - I like it!

Thanks!
Onions.
My website: http://www.harryrabbit.co.uk/electronics/home.html Up and running now! (Feel free to look round!) :D

Go Up