Null statement (NOP or CONTINUE)


Closed Thread
Results 1 to 9 of 9
  1. #1
    Join Date
    Aug 2006
    Location
    Omaha, Nebraska USA
    Posts
    263

    Default Null statement (NOP or CONTINUE)

    I have occasional need for a null statement, one which effectively does nothing. In assembly, this would be NOP; back in the good (bad?) old days of FORTRAN, it would be CONTINUE.

    I've been defining a dummy byte variable (cleverly called DUMMY) and just using

    DUMMY=0

    Is there a better solution? What, in terms of code space and/or execution time, is best?
    Last edited by RussMartin; - 4th February 2009 at 18:15.
    Russ
    N0EVC, xWB6ONT, xWN6ONT

    "Easy to use" is easy to say.

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Well, it really depend on how the above is processed by the compiler, and on which architecture as well

    Usually clearing a Variable would imply a simple asm line
    CLRF _DUMMY

    Or
    MOVLW 0
    MOVWF _DUMMY

    BUT this assume you're on the right BANK... if BANK sensitive at all. Even though, there's several way to switch between BANK... and this still bring the idea of how they do it in background.

    To me, NOP or GOTO $+1 (or GOTO $+2 for 18) are the best way, as they use a fixed instruction cycle and BANK insensitive AND you don't need any DUMMY variable AND you don't need to know the background process. But it's me
    Last edited by mister_e; - 4th February 2009 at 18:43.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    To me, NOP or GOTO $+1 (or GOTO $+2 for 18) are the best way, as they use a fixed instruction cycle and BANK insensitive AND you don't need any DUMMY variable AND you don't need to know the background process. But it's me
    Hi Steve,
    A belated Happy New Year ! I know what a nop is and does, could you explain what GOTO $+1 does ? Thank You, JS
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    GOTO $+1 just mean, jump one instruction next to the current one, $ being the current position/instruction.

    This usually eat 2 instruction cycle, while NOP eat 1 instruction cycle

    For 18F, you must use GOTO $+2
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    GOTO $+1 just mean, jump one instruction next to the current one, $ being the current position/instruction.

    This usually eat 2 instruction cycle, while NOP eat 1 instruction cycle

    For 18F, you must use GOTO $+2
    Thank You !That's interesting, It burns through 2 instructions to go where it was going anyway, so if I get this correctly . . . would it jump to any location by changing the 1 to another number, like a GOTO LABEL without the label ?
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  6. #6
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Default

    Hi Russ and Steve

    for 16F ...

    Code:
    While 0
    Wend
    
    next command
    gives in asm

    Code:
    L0001    GOTO L0002
                GOTO L0001
    L0002    .... Next Command
    Should do the trick, no ???

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  7. #7
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Alain,
    well yes or no, but it's just longer to type

    Joe
    Yes, I think you got it right.

    To make it easier...

    GOTO $+1

    is the same as
    NOP
    NOP

    well instruction-cycle wise (can I say that ??? )
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  8. #8
    Join Date
    Aug 2006
    Location
    Omaha, Nebraska USA
    Posts
    263


    Did you find this post helpful? Yes | No

    Default

    I should probably have explained:

    I don't leave the dummy statement in a finished program. Usually, it occupies a space where another function, or a GOTO, or a GOSUB will be placed.

    I really like Alain's

    WHILE 0
    WEND

    . . . which I assume I could render on one line as WHILE 0 : WEND, and then go from there.

    But the GOTO $+1 intrigues me, too. Will that work as a PBP command?
    Russ
    N0EVC, xWB6ONT, xWN6ONT

    "Easy to use" is easy to say.

  9. #9
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    yeah it will work, but you need to use the @ sign before (how it's called anyways, here we use to call it commercial A, then AT... )as it's an ASM statement

    @ GOTO $+1
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. Using SPI
    By The Master in forum Serial
    Replies: 6
    Last Post: - 14th March 2010, 15:37
  2. Trying to build an IR project
    By financecatalyst in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 10th November 2009, 23:48
  3. Hserin
    By [email protected] in forum Serial
    Replies: 11
    Last Post: - 16th December 2008, 18:49
  4. frequency meter in PBP
    By savnik in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 13th June 2007, 06:34
  5. PIC12F675 trouble
    By russman613 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 27th February 2006, 18:40

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts