Windows in-line CODE procedure.

From: [at]} <robert.d.campbell{>
Date: Tue, 27 Jun 2000 09:22:08 +0000 (GMT)

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 ?


Thanks


Robert Campbell
robert.d.campbell{([at]})nowhere.xy



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

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 - 09:22:08 UTC

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