instruction time

Hi all

1- How can I calculate the number of clock cycle for each instruction?
2- Can I make a delay less than 1microsecond?

regards

Page 537 of the AtMega328P data sheet has a full list of all instructions and their respective clock cycles.
I am not sure about less than 1us delay. Maybe with a 20Mhz crystal.

2 - Can I make a delay less than 1microsecond?

Yes, use assembly.

void loop()
{
  // do something
  // 4 nops == 0.25 usec. @16Mhz
  asm("nop"); // wait one clockcylce
  asm("nop"); // wait one clockcylce
  asm("nop"); // wait one clockcylce
  asm("nop"); // wait one clockcylce
  // do something else
}

Hi

Can I use the Assembly language in Arduino just by write the instruction in the following format?

asm(" instruction systax ");

yes, it can be done

from - http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1207370768/2 - (thanks to mungbeam)

unsigned int a = 0;

void setup() {
  Serial.begin(9600);

  a = 2;

  Serial.print("a = ");
  Serial.println(a);

    asm("mov r0,%0 \n\t"  // copy a to r0
	"inc r0    \n\t"  // increment
	"inc r0    \n\t"  // increment
	"mov %0,r0 \n\t"  // copy r0 back to a
	:  "+r" (a));

  Serial.print("now a = ");
  Serial.println(a);

}

void loop() {
}