[Oberon] Question about SYSTEM.BIT() in Oberon-7
joerg.straube at iaeth.ch
Sat Jun 5 08:40:25 CEST 2021
In Oberon-7 your procedure could look as follows
PROCEDURE DisplayIEEE754(x: REAL);
VAR s: SET;
PROCEDURE Bits(str: ARRAY OF CHAR; s: SET; left, right: INTEGER);
FOR i := left TO right BY -1 DO
IF i IN s THEN Out.Char(“1“) ELSE Out.Char(“0“) END
s := SYSTEM.VAL(SET, x);
Out.String(“sign is “); IF 31 IN s THEN Out.Ch(“-“) ELSE Out.Ch(“+“) END;
Bits(“, expo (binary): “, s, 30, 23)
Bits(“ frac (binary): “, s, 22, 0);
> Am 05.06.2021 um 01:10 schrieb R. S. Doiel <rsdoiel at gmail.com>:
> That's cool. So what I was thinking of doing is to read the address contents of my REAL variable into an INTEGER then use SYSTEM.BIT() to report out the sign, the exponent and the fraction. Reading Reals.IntL gave that idea.
> (** Convert LONGREAL to hexadecimal. h and l are the high and low parts. *)
> PROCEDURE IntL* (x: LONGREAL; VAR h, l: LONGINT);
> BEGIN SYSTEM.GET(SYSTEM.ADR(x) + H, h); SYSTEM.GET(SYSTEM.ADR(x) + L, l)
> END IntL;
> In the Native Oberon case (Oberon-2) H and L are initialized based on system expectation (my interpretation). To better understand the SYSTEM module and how it is expected to work I was wondering if this made sense in Oberon-7?
> PROCEDURE DisplayIeee754(x : REAL);
> VAR raw : INTEGER;
> SYSTEM.GET(SYSTEM.ADR(r), raw);
> IF SYSTEM.BIT(raw, 31) THEN
> Out.String("sign is -, ");
> Out.String("sign is +, "
> Out.String(" expo (binary): ");
> FOR i := 31 TO 23 BY -1 DO
> IF SYSTEM.BIT(raw, i) THEN
> Out.String(" frac (binary): ");
> FOR i := 23 TO 0 BY -1 DO
> IF SYSTEM.BIT(raw, i) THEN
> END DisplayIeee754;
> Is my understanding correct? If so then I have some compiler debugging issues to sort out and that's OK. It's helping me better understand language and approach.
> Thanks for the help!
>> On 6/4/21 3:45 PM, Joerg wrote:
>> You‘re absolutely right:
>> SYSTEM.BIT(a, 0) checks the LSB of the word at address a.
>> I guess for Reals.IntL you don‘t need SYSTEM.BIT.
>>> Am 04.06.2021 um 23:55 schrieb R. S. Doiel <rsdoiel at gmail.com>:
>>> Hello everyone,
>>> This is probably a bit of a novice question and I apologize but
>>> it has me puzzled. In the Oberon-7 language report's
>>> SYSTEM.BIT() is described as using "n" to address a specific bit.
>>> On first reading I assumed "n" zero would be the LSB and "n"
>>> thirty one would be MSB where the compiler deals with the local
>>> implementation of bit ordering. Is that the correct reading
>>> of the report?
>>> I was planning on implementing a procedure like Native Oberon's
>>> Reals.IntL() but then started having doubts about my reading of the
>>> Oberon-7 report. Have I made too simple a set of assumptions about
>>> how I should expect SYSTEM.BIT() to work under Oberon-7
>>> All the best,
>>> Robert Doiel
>>> Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related systems
>> Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related systems
> Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related systems
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Oberon