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

Post Reply
User avatar
fotios
Posts: 458
Joined: Mon Feb 08, 2010 10:17 am
Location: Greece
Has thanked: 109 times
Been thanked: 117 times
Contact:

Not sure if this macro is correct

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

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Not sure if this macro is correct

Post 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.

User avatar
fotios
Posts: 458
Joined: Mon Feb 08, 2010 10:17 am
Location: Greece
Has thanked: 109 times
Been thanked: 117 times
Contact:

Re: Not sure if this macro is correct

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

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

Re: Not sure if this macro is correct

Post 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.

Post Reply