Re: Windows in-line CODE procedure.

From: [at]} <Stewart>
Date: Tue, 27 Jun 2000 16:54:16

At 09:22 AM 27/6/00 +0000, you wrote:
>
>
>I have a series of algorithms that depend heavily on the following formula
>
>VAR
> a, b, m, x : INTEGER;
>BEGIN
> ...
> x := a * b MOD m;
>
>
>For my applications a and b are non-negative, ie in the range [0 ... 2^31
- 1].
>and m is positive, ie in the range [1 ... 2^31 - 1].
>
>The code as written is incorrect as a * b can cause INTEGER overflow.
>
>If I write
>
> x := SHORT (LONG (a) * LONG (b) MOD LONG (m));
>
>it is correct, but I suspect inefficient because the LONGINT * and MOD
>operations are defined over a larger ranger than I need.
>
>The formula can be coded in 2 68020 assembly instructions (eg - roughly!)
>
> MULS.L D0, D1:D2 ! D1:D2 <- D0 * D1
> DIVS.L D3, D1:D2 ! D1 <- D1:D2 MOD D3
>
>but I am totally ignorant of the Intel instruction set.
>
>
>Can anyone help me write a procedure with the signature
>
>PROCEDURE [code] ModMult (a, b, m : INTEGER) : INTEGER ?
>

Assuming that:
- BP is the frame pointer
- xAddr is the offset of parameter x relative to the base of the frame
- the result is returned in EAX

It would probably look something like:
  MOV EAX, [BP]+aAddr
  IMUL [BP]+bAddr
  IDIV [BP]+mAddr
  MOV EAX, EDX

Of course, these assumptions might not be correct. You may also need some
sort of prolog/epilog to manage the frame pointer. From memory, Blackbox
uses STDCALL (Pascal) calling convention so the procedure must remove its
own stack frame.

Note that IMUL multiplies EAX by a 32-bit argument, placing the result in
EDX:EAX. IDIV divides EDX:EAX by an argument and returns the quotient in
EAX and the remainder in EDX.

Hope this helps.

Cheers,
  Stewart

--------------------------------------------

To unsubscribe from this mailing list, send a message containing the word "unsubscribe" to:
   blackbox-request{([at]})nowhere.xy

To get a list of valid e-mail commands and instructions on their usage, send a message containing the word "help" to the above address.

Send any problem reports or questions related to this email list to the list owner at
   owner-blackbox{([at]})nowhere.xy
Received on Tue Jun 27 2000 - 16:54:16 UTC

This archive was generated by hypermail 2.3.0 : Thu Sep 26 2013 - 06:27:45 UTC