flat assembler
Message board for the users of flat assembler.

Index > Windows > sorting numbers

Author
Thread Post new topic Reply to topic
sina



Joined: 18 Aug 2003
Posts: 132
Location: istanbul turkey
sina 14 Dec 2003, 13:39
ok Smile i got a random number generator
i want 6 numbers and all will be different and in the range 1-49 (1 and 49 are in)
and i have 6 variables like num1 num2 num3
i want to have my 6 random numbers in an order from small to greater (ascending?) to be in my variables

here is what i have tried
Code:
  guess:

     @@:
        stdcall nrandom,50
        cmp     eax,0
        je      @b
        cmp     eax,50
        je      @b
        mov     [num1],eax
     @@:
        stdcall nrandom,50
        cmp     eax,0
        je      @b
        cmp     eax,50
        je      @b
        cmp     eax,[num1]
        je      @b
        cmp     eax,[num1]
        jg      a1
        mov     edx,[num1]
        mov     [num1],eax
        mov     [num2],edx
     a1:
        stdcall nrandom,50
        cmp     eax,0
        je      a1
        cmp     eax,50
        je      a1
        cmp     eax,[num1]
        je      a1
        cmp     eax,[num1]
        jg      a2
        mov     edx,[num1]
        mov     [num1],eax
        mov     eax,[num2]
        mov     [num2],edx
        mov     [num3],eax
        jmp      a4
     a2:
        cmp     eax,[num2]
        je      a1
        cmp     eax,[num2]
        jg      a3
        mov     edx,[num2]
        mov     [num2],eax
        mov     [num3],edx
        jmp      a4
     a3:
        mov     [num3],eax

     a4:
        invoke  SetDlgItemInt,[hwnddlg],ID_Label11,[num1],0
        invoke  SetDlgItemInt,[hwnddlg],ID_Label12,[num2],0
        invoke  SetDlgItemInt,[hwnddlg],ID_Label13,[num3],0
    

i am in the third number here and it has some errors too but i think this should not be the way to to this iy u can help me again i will be gratefull
Post 14 Dec 2003, 13:39
View user's profile Send private message ICQ Number Reply with quote
sina



Joined: 18 Aug 2003
Posts: 132
Location: istanbul turkey
sina 14 Dec 2003, 18:08
ok here is the code but its huge and slow
any improvements are welcome Smile


Description:
Download
Filename: loto.zip
Filesize: 3.51 KB
Downloaded: 675 Time(s)

Post 14 Dec 2003, 18:08
View user's profile Send private message ICQ Number Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 14 Dec 2003, 18:50
VeSCeRa wrote:
ok here is the code but its huge and slow
any improvements are welcome Smile


Good work VeSCeRa. If you make it only with 1 row (because of simplicity) it is very good example for the beginers.

Some first look improvements:
Code:
; This code...
  _num1:
        stdcall nrandom, 50
        cmp     eax,0
        je      _num1

; ... is equal to:
        stdcall nrandom,49
        add     eax,1
    


And maybe you should think about processing the numbers in some loop. The code will be smaller.

Regards.
Post 14 Dec 2003, 18:50
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
sina



Joined: 18 Aug 2003
Posts: 132
Location: istanbul turkey
sina 14 Dec 2003, 21:52
ok i will make it simple and try a loop
Post 14 Dec 2003, 21:52
View user's profile Send private message ICQ Number Reply with quote
sina



Joined: 18 Aug 2003
Posts: 132
Location: istanbul turkey
sina 14 Dec 2003, 22:34
ok the simple version
with some comments


Description:
Download
Filename: loto.rar
Filesize: 1.84 KB
Downloaded: 683 Time(s)

Post 14 Dec 2003, 22:34
View user's profile Send private message ICQ Number Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2139
Location: Estonia
Madis731 15 Dec 2003, 12:45
I don't see the point:
Code:
             jz      exit
  exit:
    

Hmm, what would it do if it weren't zero...it would still goto exit. Maybe you wanted to set some flags? or add stalls?

...but I think the 2 lines may be left out.
Post 15 Dec 2003, 12:45
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.