[Oberon] Question about SYSTEM.BIT() in Oberon-7

Joerg joerg.straube at iaeth.ch
Sat Jun 5 12:47:57 CEST 2021


Robert

Of course you can use SYSTEM.BIT the way you used it. However, SYSTEM.BIT is typically used to check HW registers like
- was a key pressed on the keyboard or
- did we receive a frame from network or
- is the bus ready to send data
- etc

Look at Input.Peek or Kernel.SPI

br
Jörg

> Am 05.06.2021 um 08:40 schrieb Jörg <joerg.straube at iaeth.ch>:
> 
> Robert
> 
> 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);
>     BEGIN
>       Out.String(str);
>       FOR i := left TO right BY -1 DO
>         IF i IN s THEN Out.Char(“1“) ELSE Out.Char(“0“) END
>       END
>     END Bits;
>   BEGIN
>     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);
>     Out.Ln
>   END DisplayIEEE754;
> 
> Gruss, Jörg
> 
>>> 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;
>> BEGIN
>>   SYSTEM.GET(SYSTEM.ADR(r), raw);
>> 
>>   IF SYSTEM.BIT(raw, 31) THEN
>>     Out.String("sign is -, "); 
>>   ELSE
>>     Out.String("sign is +, "
>>   END;
>>   Out.String(" expo (binary): "); 
>>   FOR i := 31 TO 23 BY -1 DO
>>     IF SYSTEM.BIT(raw, i) THEN
>>       Out.Char("1"); 
>>     ELSE
>>       Out.Char("0"); 
>>     END;
>>   END;
>>   Out.String(" frac (binary): "); 
>>   FOR i := 23 TO 0 BY -1 DO
>>     IF SYSTEM.BIT(raw, i) THEN
>>       Out.Char("1"); 
>>     ELSE
>>       Out.Char("0"); 
>>     END;
>>   END;
>>   Out.Ln;
>> 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!
>> 
>> Robert
>> 
>>> On 6/4/21 3:45 PM, Joerg wrote:
>>> Robert
>>> 
>>> 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.
>>> 
>>> br
>>> Jörg
>>> 
>>>> 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
>>>> implementations?
>>>> 
>>>> All the best,
>>>> 
>>>> Robert Doiel
>>>> 
>>>> 
>>>> --
>>>> Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related systems
>>>> https://lists.inf.ethz.ch/mailman/listinfo/oberon
>>> --
>>> Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related systems
>>> https://lists.inf.ethz.ch/mailman/listinfo/oberon
>> --
>> Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related systems
>> https://lists.inf.ethz.ch/mailman/listinfo/oberon
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.inf.ethz.ch/pipermail/oberon/attachments/20210605/db822e02/attachment.html>


More information about the Oberon mailing list