Re: 63/64 bit version of Delphi's function random( aRange : integer ) : integer; ?
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


sci.crypt archive

Re: 63/64 bit version of Delphi's function random( aRange : integer ) : integer; ?

From: Skybuck Flying <spam@hotmail.com>
Date: Fri Apr 28 2006 - 05:21:31 CEST

Ok,

Here is the first step in helping out with converting the assembler back to
pascal.

During compile time only these lines get a blue dot in front of them which
means the other lines aren't used:

asm
        PUSH EBX
        XOR EBX, EBX
        IMUL EDX,[EBX].RandSeed,08088405H
        INC EDX
        MOV [EBX].RandSeed,EDX
        MUL EDX
        MOV EAX,EDX
        POP EBX
end;

RandSeed is defined/declared as:

RandSeed: Longint = 0; { Base for random number generator }

This is just a 32 bit signed integer which can be set to anything (within
range ofcourse ;)).

I am not an assembler expert...

But so far when looking at this code I think it does the following:

asm
    // apperently ebx needs to be pushed onto the stack to keep it's value
    PUSH EBX

    // I know this trick ;), it's to make EBX zero.
    XOR EBX, EBX

    // don't know what this does... I never understand what [ ] means...
    // though I think/guess that it means load the value where EBX points
to..
    // but in this case that would be weird...
    // maybe it's a nill pointer I dont know.

    // it also looks like an I for integer, multiply or so.
   // H for hexadecimal.
    // looks like RandSeed is multiplied with the hexadecimal number.
    // not sure though me would have to lookup the meaning of imul etc.

   // oh yeah and store result in EDX
    IMUL EDX,[EBX].RandSeed,08088405H

   // this one is simple... increase EDX
        INC EDX

   // store edx in RandSeed probably for later use
        MOV [EBX].RandSeed,EDX

   // No idea what this means ?
   // Multiple but with what ? EBX again ? Dont know.
        MUL EDX

  // store EDX in EAX
  // EAX probably return value... pretty sure of that ;)
        MOV EAX,EDX

  // put value on stack back in EBX
        POP EBX
end;

Hmmm I can vaguely remember that MUL uses EAX to multiply with or so.. that
would make sense...

Since where does the aRange parameter go ?

Probably into EAX...

So that would mean EDX multiplied with EAX.. but why really ?

Oh well

I am just guessing.

Time to get my assembler bookie ;)

Who knows meanwhile one of you guys might beat me too it ;)

Bye,
  Skybuck.
Received on Mon May 1 02:05:22 2006