[Oberon] RISC emulator and floating-point
Paul Onyschuk
blink at bojary.koba.pl
Tue Mar 25 22:11:48 CET 2014
On Tue, 25 Mar 2014 20:49:15 +0100
Peter De Wachter <pdewacht at gmail.com> wrote:
> The compiler in Project Oberon (both the original and the current
> edition) permits integers with the sign bit set when using hexadecimal
> notation. From the compiler source code it's clear that this is
> intentional. This is used in a couple of places, for example in the
> FileDir module:
>
> CONST DirMark* = 9B1EA38DH;
> HeaderMark* = 9BA71D86H;
I think I found issue. Right now in Oberon running under emulator:
-1 DIV 10 = -1
-1 MOD 10 = 9
Is that indented behavior? Now version of procedure WriteInt() with
comments:
PROCEDURE WriteInt* (VAR W: Writer; x, n: LONGINT);
VAR i: INTEGER; x0: LONGINT;
a: ARRAY 10 OF CHAR;
BEGIN i := 0;
(* Taking this branch, since x = 80000000H = -2147483648 *)
IF x < 0 THEN
IF x = 0 THEN WriteString(W, " -2147483648")
(* Negating x results in integer overflow and x0 wraps
around to -2147483648 *)
ELSE DEC(n); x0 := -x
END
ELSE x0 := x
END;
REPEAT
a[i] := CHR(x0 MOD 10 + 30H); x0 := x0 DIV 10; INC(i)
(* Loop never terminates, since -1 DIV 10 = -1 and x0 is never 0 *)
UNTIL x0 = 0;
WHILE n > i DO Write(W, " "); DEC(n) END;
IF x < 0 THEN Write(W, "-") END;
REPEAT DEC(i); Write(W, a[i]) UNTIL i = 0
END WriteInt;
--
Paul Onyschuk
More information about the Oberon
mailing list