Journal clone53421's Journal: Lagged Fibonacci Generator (80x86)
This program implements a lagged Fibonacci generator with constants j=7, k=10. A linear congruential generator is used to seed the list of initial values; the system timer is used to seed the LCG.
Initially I included a routine to print each random number so I could redirect the output into a
Like the other ones, paste this in Notepad and save it as a
@echo off
goto batch
a
;Generates random numbers using an Additive Lagged Fibonacci Generator, j=7, k=10.
;The system timer (clock ticks since midnight) is used to seed a LCG to generate initial values
call 017d;_seed
mov ax,0012
int 10;Set video mode 12 (640x480x16 graphics)
;_loop
call 014d;_rand
mov bx,0005
xor dx,dx
div bx
shl ax,1
mov bx,0029
xor dx,dx
div bx
mov cx,ax;CX holds the column number
call 014d;_rand
mov bx,000c
xor dx,dx
div bx
mov bx,0005
mul bx
mov bx,0039
xor dx,dx
div bx
xchg ax,dx;DX holds the row number
mov ah,0c
and al,0f
int 10;plot the pixel
;Check for keypress to exit
mov ah,06
mov dl,ff
int 21
jz 0108;_loop
mov ax,0002
int 10;Set video mode 2 (25x80x16 text)
mov ax,4c01
int 21;return to DOS
;Return the next random number in AX.
;_rand
xor bh,bh
mov bl,[01a2+14];_lastValues
mov ax,[bx+01a2];_lastValues
add bx,06
cmp bx,14
jl 0162;_next1rand
sub bx,14
;_next1rand
add ax,[bx+01a2];_lastValues
;Store the new random number (AX) in the last values history
mov bl,[01a2+14];_lastValues
mov [bx+01a2],ax;_lastValues
;Increment our pointer to the oldest last value
inc bx
inc bx
cmp bx,14
jl 0178;_next2rand
sub bx,14
;_next2rand
mov [01a2+14],bl;_lastValues
ret
;Seed the random number generator using the system timer
;_seed
xor ah,ah
int 1a;Get ticks since midnight in CX:DX
mov [01a2],dx;_lastValues
mov ax,dx
xor bx,bx
;_LCG
mov dx,4e35
mul dx
inc ax
inc bx
inc bx
mov [bx+01a2],ax;_lastValues
cmp bx,12
jl 0189;_LCG
or ax,0001;LFG needs at least 1 odd initial value
mov [bx+01a2],ax;_lastValues
ret
;_lastValues
dw 0,0,0,0,0,0,0,0,0,0
db 0
;_ASCIIZ
db "lfg_snow.com",0
;_compile
MOV AX,CS
MOV DS,AX
MOV AH,3C
XOR CX,CX
MOV DX,01b7;_ASCIIZ
INT 21
MOV BX,AX
MOV CX,01b7;_ASCIIZ
MOV DX,0100 ; where the program starts
SUB CX,DX
MOV AH,40
INT 21
MOV AH,3E
INT 21
MOV AX,4C00
INT 21
r ip
1c4
g
q
:batch
if exist %0 goto extension
debug < %0.bat
goto run
:extension
debug < %0
:run
pause
cls
lfg_snow.com
Lagged Fibonacci Generator (80x86) More Login
Lagged Fibonacci Generator (80x86)
Slashdot Top Deals