EmbDev.net

Forum: µC & Digital Electronics basic knowledge - processor


Author: michael (Guest)
Posted on:

Rate this post
0 useful
not useful
hi
example:
if i start a main function with a var A = 0 and let it add one every 
cycle:
main(){
int A = 0;
A++;
}

@ 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 
A=10??

Author: Andreas Schwarz (andreas) (Admin) Flattr this
Posted on:

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
Author: michael (Guest)
Posted on:

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

Author: 6A66 (Guest)
Posted on:

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.

rgds

Author: Rene H. (Guest)
Posted on:

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 
Summary").

Regards,
René

Reply

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]
  • [avrasm]AVR assembler code[/avrasm]
  • [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.