KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I want to write a C code firmware for Atmel AVR microcontrollers. I will compile it using GCC. Also, I want to enable compiler optimizations ( -Os or -O2 ), as I see no reason to not enable them, and they will probably generate a better assembly way faster than writing assembly manually. But I want a small piece of code not optimized. I want to delay the execution of a function by some time, and thus I wanted to write a do-nothing loop just to waste some time. No need to be precise, just wait some time. /* How can it NOT optimize this, while optimizing other code? */ unsigned char i, j; j = 0; while(--j) { i = 0; while(--i); } Since memory access in AVR is a lot slower, I want i and j to be kept in CPU registers. I found util/delay.h and util/delay_basic.h from AVR Libc . Although most times it might be a better idea to use those functions, this question remains valid and interesting. Related questions: How can I prevent GCC optimizing some statements in C? Is there a way to tell GCC not to optimise a particular piece of code? How not to optimize away - mechanics of a folly function
Tags (comma-separated)
Save Edits
Cancel