I'm not even sure how to phrase the heading but here goes.
I would like to write shorter and more efficient assembler code (MPLAB PIC Microchip) to do the following...
My variable is called RxNode, and it will contain a number (decimal) from 0 to 7. (It will never fall outside of these values). Now, I want to bit switch another variable (NodeData) with the respective node address, i.e. if RxNode = 5, I want to be able to BSF of BCF NodeData,5 without affecting the rest of the Bits in NodeData
BTW, this is not homework. I would just like a method shorter than the one I’m currently using.
Thanks
I would like to write shorter and more efficient assembler code (MPLAB PIC Microchip) to do the following...
My variable is called RxNode, and it will contain a number (decimal) from 0 to 7. (It will never fall outside of these values). Now, I want to bit switch another variable (NodeData) with the respective node address, i.e. if RxNode = 5, I want to be able to BSF of BCF NodeData,5 without affecting the rest of the Bits in NodeData
Code:
NodeData 7 6 5 4 3 2 1 0
| | | | | | | |
RxNode (=7) -----+ | | | | | | |
RxNode (=6) -------+ | | | | | |
RxNode (=5) ---------+ | | | | |
RxNode (=4) -----------+ | | | |
RxNode (=3) -------------+ | | |
RxNode (=2) ---------------+ | |
RxNode (=1) -----------------+ |
RxNode (=0) -------------------+
BTW, this is not homework. I would just like a method shorter than the one I’m currently using.
Code:
...
Node_: movf RxNode,w ; Decode receiving node data
andlw 0x07 ;
addwf PCL,f ;
goto Node00 ; If RxNode = 0
goto Node01 ; If RxNode = 1
goto Node02 ; If RxNode = 2
goto Node03 ; If RxNode = 3
goto Node04 ; If RxNode = 4
goto Node05 ; If RxNode = 5
goto Node06 ; If RxNode = 6
goto Node07 ; If RxNode = 7
Node00: btfss GenPurp,3 ; Test if Node is ON
bcf NodeData,0 ;
btfsc GenPurp,3 ;
bsf NodeData,0 ;
return ;
Node01: btfss GenPurp,3 ; Test if Node is ON
bcf NodeData,1 ;
btfsc GenPurp,3 ;
bsf NodeData,1 ;
return ;
etc...
Thanks