tôi chưa thử nên không biết, cái code này tôi copy từ 1 program khác.
Code:
;****************************************************************
;* RANDOM : Generate random number *
;* *
;* Input : R0 = seed *
;* Output : R0 = result *
;* *
;* Notes : 24 cycles including call and DONE. *
;****************************************************************
; ifdef RANDOM_USED
; LIST
RANDOM movf R0 + 1, W ; 1 Assure Seed <> 0
iorwf R0, W ; 1
btfsc STATUS, Z ; 1 / 2 Nudge Seed to 1
incf R0, F ; 1 / 0
movlw 80h ; 1 Tap Bit 15
btfsc R0, 4 ; 1 / 2 Tap Bit 4
xorwf R0 + 1, F ; 1 / 0
btfsc R0, 2 ; 1 / 2 Tap Bit 2
xorwf R0 + 1, F ; 1 / 0
btfsc R0, 1 ; 1 / 2 Tap Bit 1
xorwf R0 + 1, F ; 1
rlf R0 + 1, W ; 1 C = New Bit
rlf R0, F ; 1 Rotate Left
rlf R0 + 1, F ; 1
; return
; goto DONE ; 8 + 2 Done
; NOLIST
;DONE_USED = 1
; endif