PIC14 Return Values

  • Tyler Montbriand

    This code:

    unsigned char c;

    signed char do_return(void)

    Generates this ASM:

    _do_return      ;Function start
    ; 2 exit points
    ;       .line   8; "return.c"   if(c)
            MOVLW   0x00
            BANKSEL _c
            IORWF   _c,W
            BTFSC   STATUS,2
            GOTO    _00106_DS_
    ;       .line   9; "return.c"   return(-1);
            MOVLW   0xff
            GOTO    _00108_DS_
    ;       .line   11; "return.c"  return(0);
            MOVLW   0x00
    ; exit point of _do_return

    Now, I'm no expert, but I'm fairly sure PICs do have a SINGLE INSTRUCTION designed for returning an 8-bit literal.  It reduces that mess to this:

    _do_return      ;Function start
            MOVLW   0x00
            BANKSEL _c
            IORWF   _c,W
            BTFSC   STATUS,2
            RETLW   0x00
            RETLW   0xff

    Any particular reason the optimizer misses this?

    • AP2k

      AP2k - 2007-05-14

      Quick question: does the PIC you are compiling for support the RETLW instruction? I know the 16F877 has it.


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks