Jörg wrote:
Hi To take the variable "n" into account even for MIN(INTEGER) I would change it to:
IF ROR(x, 31) = 1 THEN i:=10; DEC(n); a:="8463847412"
Now, ROR sounds nice to assembly language programmers but many HLL people will be on the wrong leg, whereas Oberon does have a native command to tackle it, which is fully understandable by all. I would rewrite to IF 31 in x THEN bla; bla; bla with the proper type conversion for 'x'. -- Groetjes Jan Verhoeven
-----Original Message----- From: Jan Verhoeven [mailto:jan@verhoeven272.nl] Sent: Friday, 28 March 2014 9:43 PM To: ETH Oberon and related systems Subject: Re: [Oberon] RISC emulator
Jörg wrote:
Hi To take the variable "n" into account even for MIN(INTEGER) I would change it to:
IF ROR(x, 31) = 1 THEN i:=10; DEC(n); a:="8463847412"
Now, ROR sounds nice to assembly language programmers but many HLL people will be on the wrong leg, whereas Oberon does have a native command to tackle it, which is fully understandable by all. I would rewrite to
IF 31 in x THEN bla; bla; bla
with the proper type conversion for 'x'.
IF 31 IN x ... is an incorrect translation of IF ROR(x, 31) = 1 ... The test should only return true if bit 31 of x is 1 *and* all the other bits of xare zero. When you are doing low-level bit-manipulation operations like this, low-level bit-manipulation operators like ROR are quite suitable. Being able to mix low-level operations with high-level code without having to resort to inline assembler is what makes today's Oberon ideal for programming embedded systems, Regards, Chris -- Chris Burrows CFB Software http://www.astrobe.com
On Fri, 28 Mar 2014 22:01:30 +1030 Chris Burrows <chris@cfbsoftware.com> wrote:
IF ROR(x, 31) = 1 ...
The test should only return true if bit 31 of x is 1 *and* all the other bits of xare zero.
When you are doing low-level bit-manipulation operations like this, low-level bit-manipulation operators like ROR are quite suitable.
Is there particular reason why absolute value isn't checked instead: x0 := -x; IF x0 < 0 THEN ... This is also integer-size agnostic. I'm asking since this looks like a proper way of checking for the same corner case when using ABS(): IF (ABS(x) < 0) THEN ... ELSE ... Hope I'm not too intrusive with this question. -- Paul Onyschuk
Hi The main change I did was to use the same output formatting statements (the thing with " ", "-" and digits) for the corner case and the normal case. I left the test for the corner case as is. There are different ways to test for the corner case Whether you write IF x = 80000000H THEN ... or IF ROR(x, 31) = 1 THEN ... is up to your gusto and the capabilities of the compiler :-) br Jörg -----Original Message----- From: Paul Onyschuk [mailto:blink@bojary.koba.pl] Sent: Freitag, 28. März 2014 13:15 To: oberon@lists.inf.ethz.ch Cc: ETH Oberon and related systems Subject: Re: [Oberon] RISC emulator On Fri, 28 Mar 2014 22:01:30 +1030 Chris Burrows <chris@cfbsoftware.com> wrote:
IF ROR(x, 31) = 1 ...
The test should only return true if bit 31 of x is 1 *and* all the other bits of xare zero.
When you are doing low-level bit-manipulation operations like this, low-level bit-manipulation operators like ROR are quite suitable.
Is there particular reason why absolute value isn't checked instead: x0 := -x; IF x0 < 0 THEN ... This is also integer-size agnostic. I'm asking since this looks like a proper way of checking for the same corner case when using ABS(): IF (ABS(x) < 0) THEN ... ELSE ... Hope I'm not too intrusive with this question. -- Paul Onyschuk -- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
Dear all,
IF ROR(x, 31) = 1 ... ... IF x = {31} ...
But x is not a SET, it's an INTEGER. And as some people have pointed out, it's not really self-documenting, nor indeed is the ROR version in the first place. In the following, I've attempted to establish the loop invariant for the the edge case: PROCEDURE WriteInt* (VAR W: Writer; x, n: LONGINT); VAR i: INTEGER; x0: LONGINT; a: ARRAY 10 OF CHAR; BEGIN IF x < 0 THEN DEC(n); x0 := -x ELSE x0 := x END; IF x0 < 0 THEN a[0] := "8"; i := 1; x0 := 214748364 ELSE i := 0 END; REPEAT a[i] := CHR(x0 MOD 10 + 30H); x0 := x0 DIV 10; INC(i) 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; Any advances on this? :) Cheers, Paul
-----Original Message----- From: Douglas G. Danforth [mailto:danforth@greenwoodfarm.com] Sent: Saturday, 29 March 2014 11:10 AM To: paulreed@paddedcell.com; ETH Oberon and related systems Subject: Re: [Oberon] Texts.WriteInt
On 3/28/2014 11:45 AM, Paul Reed wrote:
Dear all,
IF ROR(x, 31) = 1 ... ... IF x = {31} ... But x is not a SET, it's an INTEGER. IF BITS(x) = {31} ...
BITS is an extension to Oberon that is defined in Component Pascal. It is not defined in the 2013 Oberon Language Report or implemented in RISC Oberon. However, we have also implemented it as an extension to Oberon in the Astrobe Oberon compiler. For RISC Oberon the equivalent is: IF SYSTEM.VAL(SET, x) = {31} THEN ... Based on the fact that it is currently valid to use ORD to convert a SET to an INTEGER I would like to see a standard function (e.g. BITS) defined in a future Oberon Language Report that enabled you to do the converse (i.e. convert an INTEGER to a SET) without have to import SYSTEM, Regards, Chris Chris Burrows CFB Software http://www.astrobe.com
participants (7)
-
Alexander Iljin -
Chris Burrows -
Douglas G. Danforth -
Jan Verhoeven -
Jörg -
Paul Onyschuk -
Paul Reed