flat assembler
Message board for the users of flat assembler.
Index
> Windows > problem with div instruction |
Author |
|
JohnFound 28 Dec 2012, 18:00
Post the code.
|
|||
28 Dec 2012, 18:00 |
|
HaHaAnonymous 28 Dec 2012, 18:08
[ Post removed by author. ]
Last edited by HaHaAnonymous on 28 Feb 2015, 22:08; edited 1 time in total |
|||
28 Dec 2012, 18:08 |
|
dave_30 28 Dec 2012, 18:46
well,i'm trying to make a function that returns a rundom number between 2 value ranges.
here is the code: Code: proc RandomNum uses edx ebx,val1:DWORD,val2:DWORD .if [CurrentVal]=0 invoke GetTickCount mov [CurrentVal],eax .endif inc [val2] back: mov eax,[CurrentVal] .if dword [mult] = 0 imul eax,459678324 mov dword [mult],1 .elseif dword [mult] = 1 imul eax,467854123 mov dword [mult],2 .elseif dword [mult] = 2 imul eax,954762312 mov dword [mult],0 .endif mov [CurrentVal],eax xor edx,edx mov ebx,[val2] div ebx xchg eax,edx .if dword [val1] > eax mov eax,[val1] .endif .if dword [flag] = 0 mov dword [flag],1 jmp done .endif cmp eax,[OldVal] jne done cmp [OldVal],eax je back done: mov [OldVal],eax ret endp but the fucking problem is it crashes or either returns 0 or repeative numbers!i even did added check for it that if it's the same number then generate another number but still it doesn't works.i'm pretty fucking confused. |
|||
28 Dec 2012, 18:46 |
|
baldr 29 Dec 2012, 15:45
dave_30,
Why do you think this function will provide random numbers? Only one of those multipliers (second) is uneven, first is divisible by 4 and third -- by 8, thus CurrentVal quickly (around 13 calls) overflows and become 0 (and be reseeded with GetTickCount()). Another point is your transformation of [0, 2**32) to [val1, val2) range. Even if your generator has uniform distribution, output of RandomNum() will be biased toward val1 (the only case for uniform distribution will be when val1==0 and val2 is a power of 2). |
|||
29 Dec 2012, 15:45 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.