RETLW 0 and RETURN command on PIC10F222 microcontroller

Thread Starter

karka317

Joined Feb 26, 2019
18
When I am building a code in MPLAB X IDE v5.15 I get an Warning "Substituting RETLW 0 for RETURN pseudo-op". As I have researched the PIC10 series don't have return command so it changes to RETLW 0. But my question is how the code will change with the RETLW 0 command or it is the same as RETURN command?


Code:

Code:
    list p=10F222 ; list directive to define processor
    #include p10F222.inc ; processor specific variable definitions
 
    __CONFIG _MCLRE_ON&_CP_OFF&_WDT_OFF&_MCPU_OFF&_IOFSCS_4MHZ
 
 
    ;***** VARIABLE DEFINITIONS
    TEMP_VAR UDATA
    temp1 RES 1 ;DELAY REGISTER1
    temp2 RES 1 ;DELAY REGISTER2
    temp3 RES 1 ;DELAY REGISTER3
    temp4 RES 1 ;DELAY REGISTER4
    temp5 RES 1 ;TIMING REGISTER
    temp6 RES 1 ;TINING REGISTER

 
    ;**********************************************************************
    RESET_VECTOR CODE 0xFF ; processor reset vector

 
    MAIN CODE 0x000
    movwf OSCCAL ; update register with factory cal value
 
 
    INITIALIZE
    MOVLW B'0010'
    TRIS GPIO ; INITIALIZE
    CLRF ADCON0 ; ADC DISABLE
    CLRF GPIO
    MOVLW B'00001000'
    OPTION ; ENABLE GPIO2 AS A DIGITAL PORT
    CLRF GPIO
 
 
 
    START:
 
    SCAN1:
    BTFSS GPIO,1
    GOTO SCAN1
    ENSURE:
    BTFSC GPIO,1
    GOTO ENSURE
    CALL LOOP1
    COUNTDOWN:
    MOVLW 0xFF
    MOVWF temp5
    MOVLW 0xFF
    MOVWF temp6
    COUNTDOWN2:
    BTFSC GPIO,1
    GOTO RELAYACTIVATE
    DECFSZ temp5
    GOTO COUNTDOWN2
    MOVLW 0xFF
    MOVWF temp5
    DECFSZ temp6
    GOTO COUNTDOWN2
    GOTO SCAN1
 
    RELAYACTIVATE:
    BSF GPIO,0
    CALL LOOP1
    CALL LOOP1
    CALL LOOP1
    SCAN2:
    BTFSS GPIO,1
    GOTO SCAN2
    ENSURE2:
    BTFSC GPIO,1
    GOTO ENSURE2
    CALL LOOP1
    COUNTDOWN3:
    MOVLW 0xFF
    MOVWF temp5
    MOVLW 0xFF
    MOVWF temp6
    COUNTDOWN4:
    BTFSC GPIO,1
    GOTO RELAYDEACTIVATE
    DECFSZ temp5
    GOTO COUNTDOWN4
    MOVLW 0xFF
    MOVWF temp5
    DECFSZ temp6
    GOTO COUNTDOWN4
    GOTO SCAN2
 
    RELAYDEACTIVATE:
    BCF GPIO,0
    RESET
 
    LOOP1:
    MOVLW 0x00
    MOVWF temp1
    MOVLW 0xF0
    MOVWF temp2
 
    LOOP2:
    DECFSZ temp1
    GOTO LOOP2
    DECFSZ temp2
    GOTO LOOP2
    return  ;Warning:"Substituting RETLW 0 for RETURN pseudo-op"
 
 
    END
Mod edit: code tags
 
Last edited by a moderator:

AlbertHall

Joined Jun 4, 2014
12,346
Both instructions return to the calling context and neither has any effect on the status flags.
Retlw loads the specified literal value into W before the return.
Return leaves the W register unchanged.
So unless you are trying to return a value in W it makes no difference.
 

jpanhalt

Joined Jan 18, 2008
11,087
Agree on the actions, but disagree on the usefulness.

Consider as just one example loading SSPBUF in an SPI interface. There can be good reasons not to modify w reg before returning, and retlw requires an operand. One cannot predict the number of subroutines for which not changing w reg is preferred. The converse, instruction, "retlw" would be hard to live without for tables.

If it were me, I would switch to a 10F3xx chip.
 
Last edited:
When I am building a code in MPLAB X IDE v5.15 I get an Warning "Substituting RETLW 0 for RETURN pseudo-op". As I have researched the PIC10 series don't have return command so it changes to RETLW 0. But my question is how the code will change with the RETLW 0 command or it is the same as RETURN command?
/-/
There is a lot going on with your question.

For your chip, there is no RETURN instruction. As you have noticed, that instruction simply does not exist. So, your question is confusing because it does not take this into account, although you know that there is no RETURN instruction.

If you mean what is the difference between a RETLW and the instruction on another PIC that has RETURN (e.g., 10F320), yes, there is a very big difference. Your RETLW destroys the W file - that is, it returns with a new value for W. If you need to keep the value of W before you use a call, you have to save it before the call and restore it after the call. If you don't appreciate this, you will be banging your head trying to understand why your code is not working the way you think it should.

So, if there is no RETURN instruction for a 10F222, why doesn't the software just issue an error for "unknown opcode/mnemonic/directive/instruction - I might argue that it should.

Instead, it substitutes RETLW 0 and gives you a warning telling you it has done this. Interestingly, you are not likely to find RETURN listed as a pseudo-op. Probably MPLAB discretionary language because RETURN is a legitimate instruction for other PICs, so, in the case of its use with a 10F222, it treats it as a semi-legitimate pseudo-op.

As to the main part of your question, "how the code will change" - you are right to wonder about that and, in this case, you can just look - if you know where.

Go to your project directory and search for the .lst file and look at it after you use RETLW and again after you use return. Here is what the line looks like in each case.

RETLW 0
Code:
000B  0800  00026  retlw  0
  00027 ;  return
return
Code:
  00026 ;  retlw  0
Warning[227]: Substituting RETLW 0 for RETURN pseudo-op
000B  0800  00027  return
In both cases the numeric instruction 08 00 is the same and it is a RETLW 0

BUT, look at the same situation when I uses RETLW 4 vs return
Code:
000B  0804  00026  retlw  4
  00027 ;  return
return
Code:
  00026 ;  retlw  4
Warning[227]: Substituting RETLW 0 for RETURN pseudo-op
000B  0800  00027  return
Note that the code generated is, of course different.
For RETLW 4 the code is 08 04 but for return it remains 08 00. So, in the first case, W will contain 4 and in the second W will contain 0.

What happens if you use return 4? You will get an added warning for extraneous input and the numeric code for RETLW 0
Code:
  00026 ;  retlw  4
Warning[211]: Extraneous arguments on the line.
Warning[227]: Substituting RETLW 0 for RETURN pseudo-op
000B  0800  00027  return  4
The takeaway, in my opinion, is to never use "return" with a 10F222 because it is not a legitimate instruction. Always use RETLW xx which is legitimate. While return will substitute accurately for RETLW 0, it is asking for problems.

edit: fixed code tags and clarity
 
Last edited:
Top