[Oberon] FPGA - Two BYTE entities

Jörg joerg.straube at iaeth.ch
Mon Sep 25 18:02:58 CEST 2017

Thx for pointing out. Wasn't aware of this compiler behavior.
In my point of view, the only portable way of doing it is
   Read(r, b1); Read(r, b2); wd := b1 + b2*100H;

-----Original Message-----
From: Oberon [mailto:oberon-bounces at lists.inf.ethz.ch] On Behalf Of Chris Burrows
Sent: Monday, September 25, 2017 2:02 PM
To: 'ETH Oberon and related systems' <oberon at lists.inf.ethz.ch>
Subject: Re: [Oberon] FPGA - Two BYTE entities

> -----Original Message-----
> From: Oberon [mailto:oberon-bounces at lists.inf.ethz.ch] On Behalf Of
> Jörg
> Sent: Monday, 25 September 2017 4:29 PM
> To: ETH Oberon and related systems
> Cc: Oberon@
> Subject: Re: [Oberon] FPGA - Two BYTE entities
> So, if you want to port the statement
>   ReadBytes(r, i, 2)
> to Oberon-07 you would have to write
>   i := 0;
>   ReadBytes(r, SYSTEM.VAL(A, i), 2)
> You first have to declare a type of 4 bytes, then you have to
> initialize all 4 bytes of  i" to zero and only fill in the 2 lower
> ones with the bytes in the file.
> As you now are forced to use SYSTEM, you immediately detect your code
> might not be portable anymore as it depends on endianess. This code
> only works, if the endianess of the two byte entity stored in the
> file and the endianess of the variable  i" in memory are the same.

You are NOT forced to use SYSTEM in Oberon-07. You can still map arbitrary variables onto ARRAYs of BYTEs. However, the difference is now that the compiler requires that the actual parameter has the same number of BYTEs as the formal parameter. This is safer than previously as there is less likelihood of ending up with unassigned bytes and you have more control over byte-ordering / endianess. 

There are several different ways to implement your example. Here is one:

  Short = ARRAY 2 OF BYTE;
  Word = ARRAY 4 OF BYTE;
  short: Short;
PROCEDURE ShortToInt(s: Short; VAR i: Word);
  i[0] := s[0];
  i[1] := s[1];
  i[2] := 0;
  i[3] := 0;
END ShortToInt;
  Files.ReadBytes(R, short, 2);
  ShortToInt(short, i);

You can resequence the byte assignments in ShortToInt to suit whatever endianess you are trying to achieve. You can rename the procedure if endianess needs to be highlighted. You could also treat the short as signed and sign-extend the result if that is what you require. 

Chris Burrows
CFB Software

Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related systems

More information about the Oberon mailing list