Page 1 of 1

Not sure if this macro is correct

Posted: Wed May 08, 2019 8:17 am
by fotios
Hi everyone

I try to convert this ASM macro "GETBYTE_RF" to FC:

Code: Select all

1.   GETBYTE_RF:
2.   CLRF RXDATA         ;Clear RXDATA
3.   MOVLW .8              ;W = 8d
4.   MOVWF TEMP         ;Load TEMP 8d
5.   RECLOOPDAT
6.   BSF RFSCK             ;SCK = 1
7.   NOP
8.   RLF RXDATA,F         ;Rotate Left RXDATA
9.   BSF RXDATA,0         ;Set bit 0 of RXDATA
10. BTFSS RFSDI           ;Test bit SDI, skip if is set
11. BCF RXDATA,0         ;Clear bit 0 of RXDATA
12. BCF RFSCK              ;SCK = 0
13. NOP
14. DECFSZ TEMP          ;Decrement TEMP, skip if is = 0
15. GOTO RECLOOPDAT 
16. RETURN
Apparently, it is an SPI Read transaction.
I'm wondering if this code contains bugs. I.e:
In line 2. CLRF RXDATA
In line 8. RLF RXDATA, F
Given that the register RXDATA has been cleared, why it should be Rotated Left later? The result will be always zero.
Am I missing something with the destination of instruction "RLF RXDATA, F "?
It is the same register RXDATA, isn't?

Thanks

Re: Not sure if this macro is correct

Posted: Wed May 08, 2019 8:41 am
by LeighM
Hi
The code is rotating left RXDATA, then clearing or setting bit 0 of RXDATA based on the state of the SPI in.
Looping that 8 times.

Re: Not sure if this macro is correct

Posted: Wed May 08, 2019 9:38 am
by fotios
Thanks, Leigh.
You are right, I was a bit confused from the lot of macros and "GOTOs" within the code.

A further question regarding the parameter F in this instruction:

Code: Select all

8.   RLF RXDATA,F         ;Rotate Left RXDATA
Does it mean that the destination of the result is again the RXDATA register?

Thanks

Re: Not sure if this macro is correct

Posted: Wed May 08, 2019 9:49 am
by Benj
Does it mean that the destination of the result is again the RXDATA register?
Yes I believe so, the other option would be W which would store the result into the working register.