[Oberon] Understanding ORS.Mod.txt
John R. Strohm
strohm at airmail.net
Sun Jun 12 18:05:07 CEST 2016
You asked to be corrected.
Consider Ten(37).
Initially, e = 37.
37 > 0: TRUE ... ODD(37): TRUE ... 37 DIV 2 = 18
18 > 0: TRUE ... ODD(18): FALSE ... 18 DIV 2 = 9
9 > 0: TRUE ... ODD( 9): TRUE ... 9 DIV 2 = 4
4 > 0: TRUE ... ODD( 4): FALSE ... 4 DIV 2 = 2
2 > 0: TRUE ... ODD( 2): FALSE ... 2 DIV 2 = 1
1 > 0: TRUE ... ODD( 1): TRUE ... 1 DIV 2 = 0
0 > 0: FALSE *DING!*
ODD(e) tests the least significant bit (LSB) of e.
e = e DIV 2 shifts e right one bit, discarding the LSB and providing a new one.
It would be a worthwhile exercise on your part to expand the above, with the values of t and x at each step. (Note: Instrumenting the Oberon code to produce such a trace will be considered cheating.)
-----Original Message-----
From: Srinivas Nayak
Sent: Sunday, June 12, 2016 10:34 AM
To: ETH Oberon and related systems
Subject: Re: [Oberon] Understanding ORS.Mod.txt
Hmmm...
I feel...while invoking Ten(), if e=5 (say),
then immediately inside WHILE,
IF ODD(e) THEN x := t * x END ;
will be executed and x will hold a value 10.
After that e will never be ODD.
So t will gather the value 10000.
While returning, we should multiply x to t resulting 100000.
Please correct me.
With thanks and best regards,
Yours sincerely,
Srinivas Nayak
Home: http://www.mathmeth.com/sn/
Blog: http://srinivas-nayak.blogspot.in/
On 06/12/2016 08:48 PM, John R. Strohm wrote:
> "RETURN x" is correct.
>
> On exit from the loop, e = 0. (Strictly, x <= 0, but DIV preserves the sign of the dividend, so it is not possible for e to go negative.)
>
> On the pass immediately before exiting from the loop, e = 1. ODD(1) is TRUE, so x := t * x will be executed in that pass.
>
> -----Original Message----- From: Srinivas Nayak
> Sent: Sunday, June 12, 2016 8:41 AM
> To: ETH Oberon and related systems
> Subject: [Oberon] Understanding ORS.Mod.txt
>
> We see
>
> PROCEDURE Ten(e: LONGINT): REAL;
>
> VAR x, t: REAL;
>
> BEGIN x := 1.0; t := 10.0;
>
> WHILE e > 0 DO
>
> IF ODD(e) THEN x := t * x END ;
>
> t := t * t; e := e DIV 2
>
> END ;
>
> RETURN x
>
> END Ten;
>
> Should it be, RETURN x * t ?
>
>
> With thanks and best regards,
>
> Yours sincerely,
> Srinivas Nayak
>
> Home: http://www.mathmeth.com/sn/
> Blog: http://srinivas-nayak.blogspot.in/
>
> On 06/12/2016 07:01 PM, Srinivas Nayak wrote:
>> Dear Friends,
>>
>> Finally I could gather my courage to read NW's compiler implementation.
>> Hope to get your help when I get doubts.
>>
>> In ORS.Mod.txt we see
>>
>> PROCEDURE Mark*(msg: ARRAY OF CHAR);
>>
>> VAR p: LONGINT;
>>
>> BEGIN p := Pos();
>>
>> IF (p > errpos) & (errcnt < 25) THEN
>>
>> Texts.WriteLn(W); Texts.WriteString(W, " pos "); Texts.WriteInt(W, p, 1); Texts.Write(W, " ");
>>
>> Texts.WriteString(W, msg); Texts.Append(Oberon.Log, W.buf)
>>
>> END ;
>>
>> INC(errcnt); errpos := p + 4
>>
>> END Mark;
>>
>> Why we did, errpos := p + 4 ?
>> How do I understand/interpret this?
>> I was thinking, it should be errpos := p + 1 ...
>> Kindly correct me.
>>
>>
>> With thanks and best regards,
>>
>> Yours sincerely,
>> Srinivas Nayak
>>
>> Home: http://www.mathmeth.com/sn/
>> Blog: http://srinivas-nayak.blogspot.in/
> --
> Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related systems
> https://lists.inf.ethz.ch/mailman/listinfo/oberon
>
> ---
> This email has been checked for viruses by Avast antivirus software.
> https://www.avast.com/antivirus
>
> --
> 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
---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.inf.ethz.ch/pipermail/oberon/attachments/20160612/2b1779ef/attachment-0001.html>
More information about the Oberon
mailing list