RND ;xor bits 1,5,6 & 31
movlw 32 ;make sure all bits are changed
movwf count
loop movlw 0 ;use bit zero for xor
btfsc Rand,1
xorlw 1 ;flip bit 0
btfsc Rand,5
xorlw 1
btfsc Rand,6
xorlw 1
btfsc Rand+3,7 ;bit 31
xorlw 1
addlw 0xff ;move bit 0 to carry bit.
rlf Rand,f ;rotate through 32 bits
rlf Rand+1,f
rlf Rand+2,f
rlf Rand+3,f
decfsz count,f
goto loop
;now make sure no adjacent bits are 1
;copy to Acc
movfw Rand
movwf Acc
movfw Rand+1
movwf Acc+1
movfw Rand+2
movwf Acc+2
movfw Rand+3
movwf Acc+3
movlw Acc
movwf FSR
movlw 0x80
movwf count
clrf previous
oneloop btfss previous,0 ;if previous was zero we don't care
goto cont
movfw count
andwf INDF,W
btfsc STATUS,Z
goto cont
;previous and current bit are both 1
movlw 0xff
xorwf count,w
andwf INDF,f
cont clrf previous
movfw count
andwf INDF,w
btfss STATUS,Z
incf previous,f
rrf count,f
btfss STATUS,C
goto oneloop
rrf count,f
incf FSR,f
movlw Acc+4
xorwf FSR,w
btfss STATUS,Z
goto oneloop
return