[Oberon] Non Oberon code in Oberon
Chris Burrows
chris at cfbsoftware.com
Wed Jan 20 09:45:03 CET 2016
> -----Original Message-----
> From: Oberon [mailto:oberon-bounces at lists.inf.ethz.ch] On Behalf Of
> Jörg Straube
> Sent: Wednesday, 20 January 2016 5:34 PM
> To: ETH Oberon and related systems
> Subject: Re: [Oberon] Non Oberon code in Oberon
>
> Hi all
>
> If you ever have to go that low level that a BIT is your best friend
> (eg in the case you program a device driver, directly interacting
> with HW pins like interrupt masks or so), I would use the type SET in
> Oberon.
> Each element in a SET occupies one BIT by definition Set several
> bits: s := {0, 5, 7}; or s := s + {0, 5, 7};
> Set one bit INCL(s, 4); or s := s + {4};
> Reset one bit EXCL(s, 3); or s := s - {3};
> Test a bit IF 3 IN s THEN (* bit 3 in the set "s" is
> set *)
> Test several bits IF s * {5, 7} = {} THEN (* either bit 5 or bit 7 in
> "s" is set *)
>
I agree. We use these techniques extensively for programming ARM devices using Oberon-7. You will see a lot of code like this for the device drivers:
IF uartNo = UART0 THEN
pconp := pconp + {3};
(* P0.2 Bits 5:4 = 01 TXD UART0 *)
(* P0.3 Bits 7:6 = 01 RxD UART0 *)
select := select - {5, 7} + {4, 6}
ELSIF uartNo = UART2 THEN
If you look at attempts by C programmers to do something similar the results are much more obscure.
We have also used sets to implement an array of bits in a prime number generating program:
TYPE
PrimeArray = ARRAY (MaxPrimes DIV 32)+1 OF SET;
VAR
Primes: PrimeArray;
PROCEDURE* TestPrime(i: LONGINT): BOOLEAN;
VAR
j: INTEGER;
BEGIN
j := i MOD 32;
ASSERT((j >= 0) & (j <= 31));
RETURN ((j) IN Primes[i DIV 32])
END TestPrime;
Etc.
Regards,
Chris Burrows
CFB Software
http://www.astrobe.com/
More information about the Oberon
mailing list