Count instruction cycle of assembly

Status
Not open for further replies.

tinhnho

New Member
Code:
main: clrf count
      movlw 0x23
      movwf bdata
loop: rrcf bdata,f
      btfsc STATUS,C
      incf count
      movf bdata,w
      bnz loop

cycle for :
clrf = 1
movlw = 1
rrcf = 1
btfsc = 1 or 2
incf = 1
movf = 1
bnz = 1 or 2

The number cycles for that code is 39 cycles. Can anyone check it if this is right ? thanks
 
The execution time for the code will be longer due to the fact that it loops and so some sections get repeated many times. Trying to work out the timing manually would be very difficult due to the fact that the bnz instruction can be branching dependent on the outcome of two different instructions (the rrcf and inc) [Edit, actually just on the value of bdata which is dependent on count]. If you copy the code into MPLAB, set the processor to 18Fxxxx and use the stopwatch, then MPLAB will work it out for you. That really is a horrible bit of code. Looking at it again, I think you will end up with 2 different values dependent on whether the Carry flag was set prior to calling it.

Mike.
 
Last edited:
Woops, just realised you have counted the loops. I make it 38 if carry clear and 56 if carry set.

Mike.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…