On Fri, Jul 12, 2002 at 03:42:43PM -0300, Dennis Crawley wrote: > Hi all, > I need suggestions on these Algorithms, or the best way to get: > 1.DATAIN contains the bit(position) to be set in DATAOUT. > 2.DATAOUT have to be changed without change any > other bit than the position given by DATAIN. > > Ideal: BCF DATAOUT,[VALUE IN DATAIN] Which of course doesn't exists. > > Algorithm 1: 7 instr. 7 to 35 cycles > MOVLW 0X05 ; Dummy: bit to be changed (1 to 8, not 0 to 7) > MOVWF DATAIN ; (used as a decrement counter) > BSF STATUS, C ; assuming temp=0 at init. > SetBit > RLF temp,F ; > DECFSZ DATAIN,F ; > GOTO SetBit ; > MOVFW temp ;w=temp > IORWF DATAOUT,F ;set bit 5(4) living all bits untouched > > Algorithm 2: 14 instr. 12 cycles You need a setup instruction MOVF DATAIN,W > LCALL BITSELEC > CLRF PCLATH > MOVWF DATAOUT The above instruction needs to be: IORWF DATAOUT,F > > BITSELEC > ANDLW 0X0F And this instruction above needs to be: ANDLW 0x07 > ADDWF PCL,F > RETLW 0X00 > RETLW 0X01 > RETLW 0X02 > RETLW 0X04 > RETLW 0X08 > RETLW 0X10 > RETLW 0X20 > RETLW 0X40 > RETLW 0X80 Algorithm 2 is definitely along the right lines. It's better because it takes a constant amount of time to execute no matter which bit is being set. But you're on the right track. In my bytecode interpreter I used the the following fragment which is analogous to Algorithm 2 BCF STATUS,C RLF DATAIN,W ANDLW 0x0F ADDWF PCL,F BSF INDF,0 RETURN BSF INDF,1 RETURN ; ... But it's the same idea as your algorithm 2. BAJ -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics