[Oberon] ... MOD 65536

Hans Klaver hklaver at dds.nl
Thu Apr 9 10:11:56 CEST 2020


Another interesting thing in Hennessy.Mod is procedure Rand, one of the two pseudorandom number generators in it. 

The C version is: 
  
  int Rand ()
  {
    seed = (seed * 1309 + 13849) & 65535;
    return (seed);
  };

This can be translated to Oberon thus:

  PROCEDURE Rand (): INTEGER;
  BEGIN
    seed := (seed * 1309 + 13849) MOD 65536  (* use MOD 65636 to get the same output as C *)
    RETURN seed                         (* in V5 use MOD 65535 to prevent a crash in Tree *)
  END Rand;

In Oberon '... MOD 65536' produces the same pseudorandom numbers as '... & 65535' in C.
I can understand that: at the bit level '... MOD 65536' is equivalent to '... & 65535'.

But could anyone explain why '... MOD 65636' gives a crash in Tree and '... MOD 65535' does not?

That is: in System Oberon V5, using the 2016-08-02 version of the compiler; when using the 2019-01-21 version more things go wrong.  The OBNC compiler is unproblematic when the correct code ... MOD 65636 is used.

I also applied patches to the 2019-01-21 version, as suggested by Andreas Pirklbauer in his posts of 27-2-2020 and 01-03-2020, but then I get three 'reg stack' compiler errors pointing to the Time procedure.

--
Hans Klaver 


More information about the Oberon mailing list