Bitfield functions

Topics related to the use of Oberon language features
Locked
cfbsoftware
Site Admin
Posts: 493
Joined: Fri Dec 31, 2010 12:30 pm
Contact:

Bitfield functions

Post by cfbsoftware » Wed Oct 01, 2014 1:16 pm

Two in-line functions in Astrobe for Cortex-M are used to efficiently extract or update a bitfield, i.e. just a portion of 32-bit word. Each efficiently uses a single Thumb-2 instruction:
  • BFI: Bitfield Insert
    UBFX: Unsigned Bitfield Extract

Code: Select all

  PROCEDURE BFI*(VAR x: INTEGER; msb, lsb, y: INTEGER); 
  PROCEDURE BFI*(VAR x: INTEGER; bitNo, y: INTEGER); 

Code: Select all

  PROCEDURE BFX*(y, msb, lsb: INTEGER): INTEGER; 
  PROCEDURE BFX*(y, bitNo: INTEGER): INTEGER; 
x is the target variable and y is the source data. msb is the most-significant bit and lsb is the least-significant bit of the bitfield. If msb = lsb (i.e. only a single-bit is accessed) then the two parameters can be replaced by the single bitNo.

Examples of their use can be seen in the realtime clock (RTC) library module included with Astrobe.

Locked