Movwf Instruction

Status
Not open for further replies.

Suraj143

Active Member
Is this possible? I want to put some INDF values to registers starting from 50h onwards. But in the below movwf line, the Counter variable represent only the Counter address & not the value of it

Code:
incf    Counter,F
incf    FSR,F
movf    INDF,W
movwf   4Fh+Counter
 
Last edited:
If you're trying to do an indirect write, simply place the destination address in the FSR and do a movwf INDF.
 
That won't work as 0x4F + Counter will add the address value of the named constant Counter in the equates table...not the contents of the address value represented by "Counter".

Create a named constant named W_TEMP. Then try this code -

Code:
     incf      Counter,F
     incf      FSR,F
     movfw     INDF
     movwf     W_TEMP
     movfw     Counter
     addlw     0x4F
     movwf     FSR
     movfw     W_TEMP
     movwf     INDF
 
A similar method from the for moving 'n' number of bytes between 'source' and 'target' buffers;

Code:
#define source  0x20
#define target  0x50

        movlw   4               ; # of bytes to copy              |00
copy
        movwf   count           ; save byte count                 |00
        addlw   source-1        ; add source address minus one    |00
        movwf   FSR             ; prep for indirect access        |00
        movf    INDF,W          ; read source[count-1]            |00
        movwf   temp            ; save temporarily                |00
        movlw   target-source   ; buffer offset                   |00
        addwf   FSR,F           ; prep for indirect access        |00
        movf    temp,W          ; get the source[count-1] byte    |00
        movwf   INDF            ; copy to target[count-1]         |00
        decfsz  count,W         ; last byte? yes, skip, else      |00
        goto    copy            ; branch (copy another byte)      |00

Normal caveats apply, like the IRP bit setting and bank settings when accessing the 'count' and 'temp' variables.

If you haven't already, check out the .

Cheerful regards, Mike
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…