org 0x0000 nop bra Start Start clrf counter clrf output movlw 0xDA ;b'1101 1010' movwf seed Loop movlw b'10101000' ;bits <7,5,3> used to xor seed andwf seed,w movwf taps ;taps has the seed's values at those bits lslf seed,w ;sets or clears STATUS,0 w/ seed <bit7> rrf output,f ;moves seed<7> value to output<7> movlw b'10000000' andwf taps,w xorwf output,f lslf taps,f lslf taps,f movlw 0x80 andwf taps,w xorwf output,f lslf taps,f lslf taps,f movlw 0x80 andwf taps,w xorwf output,f lslf output,f rlf seed,f ;move xor'd result into seed<0> ; incf counter,f incfsz counter,f bra Loop nop end
You sort of answered your own question .... use RRF until the bits are aligned ... I would move the original random number into a temp variable and work from there.... Anyway once the bits are aligned, use a mask to AND just that bit.... i.eBut my question basically is "What is the syntax to XOR bit 0 of 'randomnumber' with bit 4 of 'randomnumber' and store it in a variable 'temp'
movf randomnumber1 ,W ; move randomnumber1 into W movwf temp1 ; move W into temp1 movf randomnumber2 ,W ; move randomnumber2 into W movwf temp2 ; move W into temp2 rrf temp1 ,F ; move bit 4 to bit 3 position rrf temp1 ,F ; move bit 3 to bit 2 position rrf temp1 ,F ; move bit 2 to bit 1 position rrf temp1 ,W ; move bit 1 to bit 0 position andlw b'00000001' ; Mask Bit 0 (was bit 4) xorwf temp2 ,W ; XOR Bit 0 (was bit 0) of temp1 with XOR Bit 0 of temp2 andlw b'00000001' ; Mask Bit 0 movwf temp3 ; Result in temp3
RND movlw 8 movwf count loop movfw Rand+3 andlw 0x48 addlw 0x38 andlw 0x40 addlw 0xc0 rlf Rand,f rlf Rand+1,f rlf Rand+2,f rlf Rand+3,f decfsz count,f goto loop return
movlw 1<<C ;mask for carry bit bcf STATUS,C btfsc Rand,6 xorwf STATUS,f btfsc Rand,5 xorwf STATUS,f btfsc Rand,1 xorwf STATUS,f btfsc Rand+3,7 xorwf STATUS,f ; the bits are all XORed and the result is in the Carry ready for shifting. rlf Rand,f rlf Rand+1,f rlf Rand+2,f rlf Rand+3,f
I am not sure I understand that last comment.You could also increment a byte and the result (of the XOR) would be bit 0 of that byte.
clrf parity btfsc Rand,6 incf parity,f btfsc Rand,5 incf parity,f btfsc Rand,1 incf parity,f btfsc Rand+3,7 incf parity,f //bit 0 of parity will be the result of the XOR
Payson's code is a little shorter when applied to a whole byte of up to 8 set bits as a result, but of course instructions must be added to extract just the "taps" from the seed for which parity is needed. Your code, of course incorporates those additional instructions as you know beforehand that the byte being examined can only have a maximum of 4 bits set and which bits to test.First the high and low nibbles were XORed. Each bit in each nibble is now the parity of itself and the same bit in the other nibble. In other words, this reduces the problem to finding the parity of one of the nibbles. This value is XORed again with itself shifted right one bit. Bits 0 and 2 are now the parity of the upper and lower half of the nibbles. Bit 0 is then incremented if bit 2 is set, creating the combined parity in bit 0.
Start clrf counter movlw 0xCA ;b'1101 1010' movwf seed movlw b'10001110' movwf taps ;mask for bits 1,2,3,7 Loop movf taps,w andwf seed,w movwf temp swapf temp,w xorwf temp,f rrf temp,w xorwf temp,f btfsc temp,2 incf temp,f lsrf temp,f rlf seed,f incf counter,f ;include next 3 instructions for finding period movlw 0xCA xorwf seed,w btfss STATUS,2 bra Loop bra Start ;max period is in count
RND ;xor bits 1,5,6 & 31 movlw 8 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 return