Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
LinkBack Thread Tools Display Modes
Old 28th February 2007, 09:31 PM   (permalink)
Default Count instruction cycle of assembly

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
tinhnho is offline  
Old 28th February 2007, 10:44 PM   (permalink)
Default

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 by Pommie; 28th February 2007 at 11:12 PM.
Pommie is online now  
Old 28th February 2007, 11:24 PM   (permalink)
Default

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

Mike.
Pommie is online now  
Reply

Bookmarks

Thread Tools
Display Modes



Similar Threads
Title Starter Forum Replies Latest
Assembly? Marks256 Micro Controllers 43 28th July 2006 04:45 PM
Clock speeds and CPU cycle loosewire Micro Controllers 3 23rd December 2004 09:10 AM
LDR and ADD in instruction cycle rds1975 Micro Controllers 1 22nd September 2004 09:21 PM
Assembly Language Question Jeggyman General Electronics Chat 6 30th January 2004 10:54 PM
Processor Instruction Format mus3na Micro Controllers 1 19th January 2004 07:13 PM



All times are GMT. The time now is 07:37 AM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

eXTReMe Tracker