How many instruction cycles?

Status
Not open for further replies.
I am trying to work out how many instruction cycles a subroutine takes.
It has a lot of loops and goes back and foward and would drive me insane couning each cycle.

Is there an easy way to work out how many insctuction cycles a routine takes?
Like a program for example?

Can you do it in MPLAB?
as in paste a section of code in, get it to run it, and it counts each cycle?
 
For example.

The routine below.
I know I can follow the routine through, and count each cycle, but is there and easier way to calculate it?

Code:
DELAY_Xms
        MOVLW   0xCE
        MOVWF   0x20
        MOVLW   0x08
        MOVWF   0x21
        MOVLW   0x01
        MOVWF   0x22
        Call    DELAY
        RETURN

DELAY
        DECFSZ  0x20, f
        GOTO    $+2
        DECFSZ  0x21, f
        GOTO    $+2
        DECFSZ  0x22, f
        GOTO    DELAY
        RETURN
 
Use the simulator and stopwatch in MPLAB. Place a breakpoint on the first and last lines. Hit F9 and zero the stopwatch at the first breakpoint. Hit F9 again and see how many cycles it takes.

Mike.
 
That error is normally because you put the breakpoint on a line with no instruction or you have inserted lines in your code and not reassembled. Try reassembling and running again.

Mike.
 
Here's a more general purpose fixed delay subsystem you might like to simulate Jake.

Regards, Mike

Code:
delayhi equ     0x20

;******************************************************************
;  K8LH DelayCy() subsystem macro generates four instructions     *
;******************************************************************
        radix   dec
clock   equ     4               ; 4, 8, 12, 16, 20 (MHz), etc.
usecs   equ     clock/4         ; cycles/microsecond multiplier
msecs   equ     clock/4*1000    ; cycles/millisecond multiplier

DelayCy macro   delay           ; 11..327690 cycle range
        movlw   high((delay-11)/5)+1
        movwf   delayhi
        movlw   low ((delay-11)/5)
        call    uDelay-((delay-11)%5)
        endm

;******************************************************************
;  example code for simulation testing                            *
;******************************************************************
        org     0x000
        radix   dec
SimTest
        DelayCy(12*msecs)       ; <- put simulator PC here
        goto    $               ; <- put simulator break point here

;******************************************************************
;  K8LH DelayCy() subsystem 16-bit uDelay(11..327690 cycle) sub-  *
;  routine uses Mike Bond's 4-word 5-cycle 16-bit timing loop     *
;                                                                 *
;  9 words, 1 RAM variable, 14-bit core                           *
;******************************************************************
        nop                     ; entry for (delay-11)%5 == 4     |B0
        nop                     ; entry for (delay-11)%5 == 3     |B0
        nop                     ; entry for (delay-11)%5 == 2     |B0
        nop                     ; entry for (delay-11)%5 == 1     |B0
uDelay  addlw   -1              ; subtract 5 cycle loop time      |B0
        skpc                    ; borrow? no, skip, else          |B0
        decfsz  delayhi,F       ; done?  yes, skip, else          |B0
        goto    uDelay          ; do another loop                 |B0
        return                  ;                                 |B0
;******************************************************************
 
Last edited:
set up a timer, clear it just befor you do what you want to test, then read it after return and display it.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…