flat assembler
Message board for the users of flat assembler.

Index > Main > need help with rand function.

Author
Thread Post new topic Reply to topic
Hayden



Joined: 06 Oct 2005
Posts: 132
Hayden 20 Mar 2007, 19:36
The com file below attempts to create a random 8.3 mode compatable filename. The problem is I can't figure out the best way to do the rand

My rand part has an obvious floor where may put the machine into an infanite loop.

I've thought of adjusting for this in a few ways;

* Implement a 'tap bit' or something ?
* if CL even then SHR 1 bit ?

Code:
ORG 100h
USE16

init:
    mov bx, BiosClockTick
    mov di, RandomDOSName
    xor cx, cx
    mov cl, 8d
rand:
    mov al, [bx]
redo:              ; redo: needs some sorting out
    rol al, cl
    and al, 127d
num:
    cmp al, '0'    ; check for a valid digit
    jb char        ; nope, so check for char
    cmp al, '9'    ; check digit between 0-9
    jb redo        ; yes
char:
    cmp al, 'A'    ; check for a valid char
    jb redo        ; nope, so redo
    cmp al, 'Z'    ; check char between A-Z
    ja redo
next:
    cld
    stosb
    loop rand
puts:
    mov dx, RandomDOSName
    mov ax, 0900h
    int 21h
    int 20h

BiosClockTick =  046Ch
RandomDOSName dq ?
TempExtention db '.TMP'
DOSTerminator db '$'

    

_________________
New User.. Hayden McKay.
Post 20 Mar 2007, 19:36
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 20 Mar 2007, 19:52
To avoid infinite loop you could try getting "AL := AL MOD ('9'-'0'+'Z'-'A'+2)" and then mapping AL to the appropiate char (AL < 10 then AL := AL+'0' else AL := AL + 'A')
Post 20 Mar 2007, 19:52
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1900
DOS386 20 Mar 2007, 20:16
Quote:
avoid infinite loop you could try getting "AL := AL MOD ('9'-'0'+'Z'-'A'+2)"


AL := AL MOD 36 Laughing

Quote:
and then mapping AL to the appropiate char (AL < 10 then AL := AL+'0' else AL := AL + 'A')


Right ... Idea

but there seem to be more problems:


Code:
    mov bx, BiosClockTick
    mov al, [bx] 
    


Will this read from correct address at all ? Confused

And: even if you fix 2 previous problems, there is one more left:
the complete "randomness" depends of one single byte,
you will get mostly only 256 different "random" names Sad
Repeated reading from BiosClockTick will almost never give new
values ... the code will be far too fast as soon as you get rid of the
infinite loop Sad

You should use 2 bytes from BiosClockTick (the 2 highest bytes are bad
as well - mostly 0), read from there one time only ... yeah ...
only 65536 names possible ...

_________________
Bug Nr.: 12345

Title: Hello World program compiles to 100 KB !!!

Status: Closed: NOT a Bug
Post 20 Mar 2007, 20:16
View user's profile Send private message Reply with quote
Hayden



Joined: 06 Oct 2005
Posts: 132
Hayden 21 Mar 2007, 12:45
Thanks very much for giving me some direction guys. I acctualy expected the code not to work when I wrote it.

I think I should use mov 0:[bx] , or an overide segment set to zero.
I have thought about doing a rand 0 -> 25 + 'a' approach. but that would limit name sto smallcase.
Post 21 Mar 2007, 12:45
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1900
DOS386 22 Mar 2007, 05:46
Quote:
to create a random 8.3 mode compatable filename


Quote:
doing a rand 0 -> 25 + 'a' approach. but that would limit name sto smallcase.


1. From 8.3, I assumed DOS - and DOS filenames are always UPPERCASE. Shocked

2. You randomness is insufficient already for (A...Z)&(0...9), you should
forget about lowercase for now.

_________________
Bug Nr.: 12345

Title: Hello World program compiles to 100 KB !!!

Status: Closed: NOT a Bug
Post 22 Mar 2007, 05:46
View user's profile Send private message 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.