I've written a simple program - it generates signals over Port D at 4 MHz:
#include <Arduino.h>
int main(void) {
DDRD = B11111111;
PORTD = B00000000;
while (true) {
PORTD = 0;
PORTD = 5;
PORTD = 10;
PORTD = 15;
PORTD = 20;
PORTD = 25;
PORTD = 30;
PORTD = 35;
PORTD = 40;
}
return 0;
}
and this is the signal coming out on D4:

I've modified the program by inserting NOP after each assignment to POTRD:
#define NOP __asm__ __volatile__ ("nop\n\t")
int main(void) {
DDRD = B11111111;
PORTD = B00000000;
while (true) {
PORTD = 0;NOP;
PORTD = 5;NOP;
PORTD = 10;NOP;
PORTD = 15;NOP;
PORTD = 20;NOP;
PORTD = 25;NOP;
PORTD = 30;NOP;
PORTD = 35;NOP;
PORTD = 40;NOP;
}
return 0;
}
and now signal looks fine, but frequency is limited to 800 KHz:

What is the reason for interference at 4 MHz? Is there a limitation to maximal frequency on digital out? I do not really need it for some particular project, just wanted to know it.
I've asked this question on stackoverflow, but then I've discovered this dedicated forum so... I've decided to try it out ;)

avr-objdump -S /tmp/sketchname.elfand look at the generated assembler code. You'll see how many operations certain code requires. – Gerben May 14 '15 at 12:54