[Oberon] FPGA - Bitfield operations
joerg.straube at iaeth.ch
Thu Aug 16 15:10:16 CEST 2018
My Pack() would be:
ctime := ss + 100H * mm + 1000H* hh;
Am 16.08.18, 14:52 schrieb "Oberon im Auftrag von Chris Burrows" <oberon-bounces at lists.inf.ethz.ch im Auftrag von chris at cfbsoftware.com>:
> From: Oberon [mailto:oberon-bounces at lists.inf.ethz.ch] On Behalf Of
> Jan de Kruyf
> Sent: Thursday, 16 August 2018 7:23 PM
> To: ETH Oberon and related systems
> Subject: Re: [Oberon] FPGA - Simple OOP example
> For Oberon to be a real alternative I would minimally need:
> 1. single bit variables.
> 2. packed arrays of those.
> 3. if at all possible multi bit variables (2, 3, 4, 5 etc.)
> 4. packed
> records of single and multi bit variables.
I have also been thinking about ways to implement the very same set of features. E.g. something similar to the way PACKED RECORDS works with subranges in Pascal but with some finer control over alignment and endian issues etc.
Two aspects of programming the ARM Cortex-M devices have triggered these thoughts:
1. Microcontroller designers cram many different values of different data types into a single 32-bit word. This requires many packing / unpacking / type casting operations to get at the values.
2. The 'Thumb-2' instruction set used in the ARM Cortex-M3, M4 and M7 microcontrollers has efficient 'bitfield' instructions.
So far I just have used the simplest approach by implementing these instructions directly as SYSTEM functions. SYSTEM.BFI is Bitfield Insert and SYSTEM.UBFX is Unsigned Bitfield extract. The following examples illustrate this. E.g. hours are stored in a time variable as a 5-bit value in bits 20..16
PROCEDURE* Pack*(hh, mm, ss: INTEGER; VAR ctime: INTEGER);
t := ss;
SYSTEM.BFI(t, 13, 8, mm);
SYSTEM.BFI(t, 20, 16, hh);
ctime := t
PROCEDURE* Unpack*(ctime: INTEGER; VAR hh, mm, ss: INTEGER);
SYSTEM.UBFX(ss, ctime, 5, 0);
SYSTEM.UBFX(mm, ctime, 13, 8);
SYSTEM.UBFX(hh, ctime, 20, 16)
In case you are wondering the missing bits 6, 7, 14, 15, 21, 22, 23 and 27..31 are reserved and bits 26..24 represent the day of the week (0..6)!
I hope to have some more to say on this subject in the not too distant future ...
Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related systems
More information about the Oberon