Forum: µC & Digital Electronics basic knowledge - processor

von michael (Guest)

Rate this post
0 useful
not useful
if i start a main function with a var A = 0 and let it add one every 
int A = 0;

@ atmega 8 with 3.6mhz is 2.7 *10^-7 sec.

when there is no interrupt and i stop after eg. 10 cycles, is there 

von Andreas S. (andreas) (Admin) Flattr this

Rate this post
0 useful
not useful
First of all, unless A is declared volatile 
(http://en.wikipedia.org/wiki/Volatile_variable), the compiler will 
probably remove your code altogether, since it has no effect.

Assuming you meant
while(1) { A++; }
you won't get one increment per cycle, because the increment and jump 
instruction together take more than one cycle.

: Edited by Admin
von michael (Guest)

Rate this post
0 useful
not useful
yeah thats exactly what i wanna know.
does every command use one cycle?

von 6A66 (Guest)

Rate this post
0 useful
not useful
michael wrote:
> does every command use one cycle?

Hello Michael,

you wanna look up the assembler listing of your code to find out what 
the compiler generated. After that you wanna look up the datasheet of 
the prcessor to find out how many (machine-) cycles each instruction 
requires, including the loop back. That gives you a exact numer of clock 
cycles required and therefore the exact time required for execution.


von Rene H. (Guest)

Rate this post
0 useful
not useful
Hi Michael,

to be sure, you have to disassemble your compiled code, cause there are 
many assembler instructions which needs more than one cycle e.g. RET 
needs 5 cycles (just take a look at the data sheet, Chapter "Instruction 



Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]

Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.