[an error occurred while processing this directive] [an error occurred while processing this directive]
А вот еще. MSP430.
(«Телесистемы»: Конференция «Микроконтроллеры и их применение»)
[an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive]

Отправлено Alexandr 06 декабря 2001 г. 10:44
В ответ на: Пример для 32-битного генератора отправлено Бав 06 декабря 2001 г. 09:30

;
; INITIALIZE CONSTANTS FOR RANDOM NUMBER GENERATION
;
SEED .set 21845 ; Arbitrary seed value (65536/3)
MULT .set 31821 ; Multiplier value (last 3
; Digits are even–2–1)
INC .set 13849 ; 1 and 13849 have been tested
HW_MPY .set 0 ; 1: HW–MPYer on chip
;
; ALLOCATION RANDOM NUMBER IN RAM–ADDRESS 200h
;
.bss Rndnum,2,0200h
;
; SUBROUTINE: INITIALIZE RANDOM NUMBER GENERATOR:
; Load the SEED value and produce the 1st random number
;
INIRndnum .equ $ ; Uses Rndnum16
MOV #SEED,Rndnum ; Initialize generator
;
; SUBROUTINE: GENERATES NEXT RANDOM NUMBER
; HW_MPY = 0: 169 cycles
; HW_MPY = 1: 26 cycles
;
Rndnum16 .equ $
.if HW_MPY=0 ; No MPYer
MOV Rndnum,IROP2L ; Prepare multiplication
MOV #MULT,IROP1 ; Prepare multiplication
CALL #MPYU ; Call unsigned MPY (5.1.1)
ADD #INC,IRACL ; Add INC to low word of product
;
; Overwrite old random number with low word of new product
;
MOV IRACL,Rndnum ; Result to Rndnum and IRACL
.else ; HW MPYer on chip
MPYU Rndnum,#MULT ; Rndnum x MULT
MOV &ResLo,Rndnum ; Low word of product
ADD #INC,Rndnum ; Add INC to low word
.endif
RET ; Random number in Rndnum
EXAMPLE: Use of the Random Generator (1st call and succeeding calls).
;
; First call: produce the 1st random number
;
CALL #INIRndum ; Initialize generator
....
; Second and all other calls to get the next random number
;
CALL #Rndnum16 ; Next random number to register
.... ; IRACL and location Rndnum

Составить ответ  |||  Конференция  |||  Архив

Ответы



Перейти к списку ответов  |||  Конференция  |||  Архив  |||  Главная страница  |||  Содержание  |||  Без кадра

E-mail: info@telesys.ru