51for statement execution cycle

#include<reg51.h>

void delay()

{unsigned char n;

for(n=0;n<100;n++)

;

   }

void main(void)

{while(1)

  {P0=0X00;

delay();

P0=0XFF;

delay();

  }

    }

01 CLR A; clear A

02 C: 0011 MOV R7, A; A the working register to the

03 INC R7; R7 will be a plus

04 CJNE R7,0x64; if R7 is not equal to 0x64 (6 * 16 + 4 = 100) then go to C: performing at 0011

It consumes one machine cycle CLR

It consumes one machine cycle MOV

INC consumes one machine cycle

CJNE consumes two machine cycles

The cycling conditions were 03 lines and 04 rows to perform 100 times (0x64 = 100) so the above procedure consumes machine cycles N = 1 + 1 + (1 + 2) X100 = 302

Therefore, a heavy cycle for statement

for(i=0;i<n;i++) 

Number of machine cycles: N = 3XN + 2 (n must be unsigned char)

 

Dual loop for (i = 0; i <m; i ++)

for(i=0;i<n;i++)

;

Machine cycle: N = 3XmXn + 5m + 2

 

Released nine original articles · won praise 2 · Views 2604

Guess you like

Origin blog.csdn.net/sqm472527736/article/details/82632921