1

I am a beginner with asm and embedded systems. I was looking at code which is meant to clear memory locations using the "indirection" register (or something like that - not sure). The code goes like:

    movlw 0x20
    movwf FSR
loop    clrf INDF
    incf FSR, F
    btfsc FSR, 7
    goto loop

I don't get the incf FSR, F part. The instruction incf takes two operands; it increments value in the first location, and stores the result in the 2nd. In this case F will have the incremented value, then why do we do a test on FSR?

4

3 回答 3

2

F mean file register, it is a code d (destination) select bit; d = 0: store result in W, d = 1: store result in file register f. Default is d = 1.

The compiler should understand:

;Increment FSR byte and result store back to FSR
    incf FSR, F
    or
    incf FSR, 1
;Increment FSR byte and result store to W reg
    incf FSR, w
    or
    incf FSR, 0
于 2011-05-11T18:49:31.777 回答
0

incf is increment file register. The second argument is the destination, which is either the register itself (F) or the working register (W), and actually is a flag. PIC instructions can have only one file register address so you are incrementing FSR which is the only register in your instruction. There is no such thing as register F.

Read the instruction set reference for your flavour of PIC carefully.

于 2011-05-11T17:24:34.413 回答
0

Ok F just means a memory location. treat the "FSR" as just variable a pointer to a memory location.

            movlw 0x20     // put's the number 0x20 into the W register
            movwf FSR      // put's condense of W register in memory Loc "FSR"       
    loop    clrf INDF      // clear location pointed at by the value in W register. 
            incf FSR, F    // increment the content of the FSR
            btfsc FSR, 7   // test bit7 in the FSR and skip if set (exiting the loop)
            goto loop      // go back to loop. and do next memory location.

now the problem I see in this is it will exit the first run through as FSR = 0x20 thus bit 7 is clear so it exits the loop. so I wonder if the btfsc should be a btfss. then it would loop from 0x20 to 0xF0 which would make more sense.

于 2012-08-07T23:47:14.937 回答