Bitfield functions
Posted: 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:
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.
- 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;
Examples of their use can be seen in the realtime clock (RTC) library module included with Astrobe.