Home > other >  How to calculate number of instruction cycles?
How to calculate number of instruction cycles?

Time:08-09

What is the number of instruction cycles for EastLoop block? I have the following code:

   #include 
   __config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF)

   cblock 0x20
Delay1
Delay2
Delay3
    endc

    org 0
Start:
    bsf       STATUS,RP0
    clrf      TRISIO
    bcf       STATUS,RP0
    clrf       Delay1
    clrf       Delay2
    clrf       Delay3
    movlw     0xD0
    movwf     B'100000'
    movlw     .7
    movwf     CMCON
MainLoop:
    bsf       GPIO,GP1
    bsf       0x21,5
EastLoop:
    nop
    decfsz    Delay1,f
    goto      EastLoop
    decfsz    Delay2,f
    goto      EastLoop
    movwf     Delay3
    bcf       0x05,1
    bsf       0x05,4
    decf      Delay3,0
    bsf       0x20,7
    bsf       0x20,3
    bsf       O'40',1
    comf      .32,1
NordLoop:
    decfsz    Delay1,f
    goto      NordLoop
    btfsc     GPIO,GP1
    goto      SetStep
    bsf       GPIO,GP1
    goto      SetSStep
SetStep:
    bcf       GPIO,GP1
SetSStep:
    decfsz    Delay3,f
    goto      NordLoop
    bcf       0x05,1
    bcf       0x05,4
    end

Could someone please explain this?

CodePudding user response:

The processor executes assembly instructions in different instruction cycles (according to the complexity of the instruction). You can learn about instruction cycles by reading the datasheet. The total number of instruction cycles is the sum of all instruction cycles according to the program logic. According to the datasheet, the instruction cycles of some of the commands above are as follows:

Mnemonic Cycles
NOP 1
DECFSZ 1 (2) *
GOTO 2
MOVWF 1
BCF 1
BSF 1
DECF 1
COMF 1

(*) DECFSZ → If the result is 0, then a NOP is executed instead, making it a 2 TCY instruction.

Related Links

CodePudding user response:

I guess you are working with MPLABx. In this case you could count the number of instruction cycles with the stopwatch of the simulator:

  • put the PC at the top of Eastloop
  • start the stopwatch and reset it to zero
  • step thru the loop and the cycles will be count
  • Related