[Oberon] Use of DIV and MOD for bit manipulation

Srinivas Nayak sinu.nayak2001 at gmail.com
Tue Jul 12 03:39:51 CEST 2016


Thank you Jorg.
Yes, I can also see use of ASR and ROR in ReadNum and WriteNUm.


With thanks and best regards,

Yours sincerely,
Srinivas Nayak

Home: http://www.mathmeth.com/sn/
Blog: http://srinivas-nayak.blogspot.in/

On 07/11/2016 06:21 PM, Jörg wrote:
> Srinivas
>
> Good question. The intention of Oberon was to be on one side a high-level
> language but nevertheless be able to write low-level code wherever
> interaction with HW is needed (device drivers, compilers...)
>
> In the past, Wirth found that it is not necessary to foresee special
> language constructs for this kind of low level programming. If bitwise AND
> and OR are needed, use the type SET instead of INTEGER. He thought that
> almost all needed bit manipulations can be done by applying standard
> language constructs like DIV, MOD and *.
> In his former languages Modula-2 and Oberon the only special language
> construct for bit manipulation was the standard procedure ASH.
>
> Over the time it seems he changed his way of thinking. In Oberon-07 these
> special language constructs were introduced: LSL, ASR and ROR. And if
> urgently needed, you can even make use of SYSTEM.BIT, SYSTEM.LSH and
> SYSTEM.ROT.
>
> So, basically using DIV, MOD and * (with powers of two) is for Oberoners the
> "normal" way to shift bits.
>
> In ORG.Mod you will find in procedures MulOp, DivOp the special handlings
> for power of two.
>    DivOp
>      div --> ASR
>      mod --> AND
>    MulOp --> LSL
>
> Jörg
>
> -----Original Message-----
> From: Oberon [mailto:oberon-bounces at lists.inf.ethz.ch] On Behalf Of Srinivas
> Nayak
> Sent: Samstag, 9. Juli 2016 15:20
> To: ETH Oberon and related systems <oberon at lists.inf.ethz.ch>
> Subject: [Oberon] Use of DIV and MOD for bit manipulation
>
> Dear All,
>
> While reading compiler code(OBG.Mod.txt),
> I see that in many places we have used DIV, MOD, multiplication etc.
> No doubt, one can argue that, we want to do a mathematical operation there,
> but to be honest, the interest there is not to do a mathematical operation;
> rather to do some bit manipulation.
> And, since we know that DIV and MOD can help us there, we employ them.
>
> How shall we justify it (to obscure the natural meaning)?
> Isn't the code clarity being compromised there?
>
> I would like to know, how Oberoners think about it...
>
>
> 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
>
> --
> Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related systems
> https://lists.inf.ethz.ch/mailman/listinfo/oberon
>


More information about the Oberon mailing list