Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] [Moved] how many instruction cycles?

Status
Not open for further replies.

metals

Junior Member level 2
Junior Member level 2
Joined
Jan 25, 2011
Messages
22
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,441
In assembly language for programming PIC, how many instruction cycles would this code take?

Code:
hugo    movlw    0x14
          movwf    n
igen     decf      n,f
          bnz       igen
          nop
          nop
          rlncf      n,w
          movwf   portC
          nop
          return

I know that they all take 1 instruction cycle except for bnz which ned 1 or 2 and return that also need 2. But the answer is not 11/12 instruction cycles?
 

Re: how many instruction cycles?

Your loop counter is 20 (0x14) so it will take a'lot longer than 11/12 cycles.

Keith
 

Yes I am using MPLAB SIM, but somehow I can not really interpret the results.

I will post i pic, do you think this is the right answer? 57 cycles?

bbv.png


Your loop counter is 20 (0x14) so it will take a'lot longer than 11/12 cycles.

I didn't think about that. But even if a count the cycles manually I only get 48, so which one is right? 48 or 57?

I counted like this:

Code:
        movlw  0x14     <--- 1 x 1
        movf    n                <--- 1 x 1
igen   decf    n,f                 <----1 x 20
        bnz     igen             <----2 x 20
        nop                       <----1 x 1
        nop                       <----1 x 1
        rlncf    n,w               <----1 x 1
        movwf portC              <----1 x 1
        return                    <----1 x 2
 

And now when I used stopwatch I got 88 instruction cycles :S
bbv22.jpg
 

Hi,

You do not seem to have used any breakpoints, so the program will have recorded all instructions, you should Zero the counter when you start your routine and stop it with a break point at the Return instruction.

Also not clear which chip you are using, your original code shows 18F instructions, your last entry has changed, could be 16F or 18F code ?
 

I used the "Step into" function so I could follow every instruction step by step. I think that is ok?
So I restarted the processor with F6 and then "Step into" line by line.

The chip I am using is a 16F877
 

Hi,

The Stopwatch I showed was run on a 18F because the code you gave used 18F instructions, RLFCF

If I run your latest code on a 16F877a then I agree with what you got.

Question for you - how long is 1 instruction cycle and where does it come from..?
 

movlw 0x14 <--- 1 x 1
movf n <--- 1 x 1

igen decf n,f <----1 x 20
btfss STATUS, Z <----1 x 19 + 1 x 2
goto igen <----2 x 19

; bnz igen <---- No such instruction on PIC16


nop <----1 x 1
nop <----1 x 1
rlcf n,w <----1 x 1
movwf portC <----1 x 1
return <----1 x 2

= 88
 

Hi,

The Stopwatch I showed was run on a 18F because the code you gave used 18F instructions, RLFCF

If I run your latest code on a 16F877a then I agree with what you got.

Question for you - how long is 1 instruction cycle and where does it come from..?

Oh I didn't think about that. hmm this is a exercise I got from school, and since we usually use our 16F I assumed the code should be run on that.
But if RLFCF can't be used with 16F then it is probably supposed to be run on a 18F.

But still, when I do it manually I do something wrong because I get 48 cycles?



1 instruction cycle is 4 clock pulses, because it usually take 1 clock pulse to fetch the instruction, then to read it, to process at and the maybe write it out.
Was the answer right? :)
 

movlw 0x14 <--- 1 x 1
movf n <--- 1 x 1

igen decf n,f <----1 x 20
btfss STATUS, Z <----1 x 19 + 1 x 2
goto igen <----2 x 19

; bnz igen <---- No such instruction on PIC16


nop <----1 x 1
nop <----1 x 1
rlcf n,w <----1 x 1
movwf portC <----1 x 1
return <----1 x 2

= 88


Hi,

Hmmm, missed the BNZ insruction and with the 16F877 it does not show a compile error ??

Here is the corrected code to replace the BNZ

Note that the Return instruction is invalid as no Call has been made for it to return to on completing the subroutine.
 

Attachments

  • 000040.jpg
    000040.jpg
    23.5 KB · Views: 122

movlw 0x14 <--- 1 x 1
movf n <--- 1 x 1

igen decf n,f <----1 x 20
btfss STATUS, Z <----1 x 19 + 1 x 2
goto igen <----2 x 19

; bnz igen <---- No such instruction on PIC16


nop <----1 x 1
nop <----1 x 1
rlcf n,w <----1 x 1
movwf portC <----1 x 1
return <----1 x 2

= 88

So you replaced bnz with goto?
 

Hi,

Hmmm, missed the BNZ insruction and with the 16F877 it does not show a compile error ??

MPASM regards BNZ (and other conditional branches BZ. BNC, BC etc) as a built-in pseudo instruction and replaces it with the btfss STATUS, Z (or other conditional test for Z NC, C etc) and goto instructions.

- - - Updated - - -

So you replaced bnz with goto?

You didn't look very hard did you?
 
  • Like
Reactions: wp100

    wp100

    Points: 2
    Helpful Answer Positive Rating
newfound

Oh now I see what you did.


So with the chip I am using (16F) it is 88 cycles, but lets say we use the 18F chip then it is 75 cycles?
 

movlw 0x14 <--- 1 x 1
movf n <--- 1 x 1
igen decf n,f <----1 x 20
bnz igen <----2 x 19 + (1 x 1)
nop <----1 x 1
nop <----1 x 1
rlncf n,w <----1 x 1
movwf portC <----1 x 1
return <----1 x 2

= 67
 
  • Like
Reactions: metals

    metals

    Points: 2
    Helpful Answer Positive Rating
movlw 0x14 <--- 1 x 1
movf n <--- 1 x 1
igen decf n,f <----1 x 20
bnz igen <----2 x 19 + (1 x 1)
nop <----1 x 1
nop <----1 x 1
rlncf n,w <----1 x 1
movwf portC <----1 x 1
return <----1 x 2

= 67

Second last before return, you forgot a NOP, so total 68 cycles?
And btw I am wondering about BNZ igen. Why is there a + (1 x 1)?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top