Not sure if this macro is correct

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

User avatar
fotios
Posts: 398
Joined: Mon Feb 08, 2010 10:17 am
Location: Greece
Has thanked: 80 times
Been thanked: 97 times
Contact:

Not sure if this macro is correct

Postby fotios » Wed May 08, 2019 8:17 am

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
Best Regards FOTIS ANAGNOSTOU

User avatar
LeighM
Matrix Staff
Posts: 1845
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 429 times
Been thanked: 612 times
Contact:

Re: Not sure if this macro is correct

Postby LeighM » Wed May 08, 2019 8:41 am

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.
These users thanked the author LeighM for the post:
fotios (Wed May 08, 2019 9:33 am)
Rating: 5.56%
 

User avatar
fotios
Posts: 398
Joined: Mon Feb 08, 2010 10:17 am
Location: Greece
Has thanked: 80 times
Been thanked: 97 times
Contact:

Re: Not sure if this macro is correct

Postby fotios » Wed May 08, 2019 9:38 am

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
Best Regards FOTIS ANAGNOSTOU

User avatar
Benj
Matrix Staff
Posts: 14157
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4330 times
Been thanked: 4080 times
Contact:

Re: Not sure if this macro is correct

Postby Benj » Wed May 08, 2019 9:49 am

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.
These users thanked the author Benj for the post:
fotios (Wed May 08, 2019 9:55 am)
Rating: 5.56%