*DECK SSBSBF
PROC SSBSBF (TABLE, ORD, BIT, LEN, SOURCE);
# TITLE SSBSBF - STORE BITFIELD IN A TABLE. #
BEGIN # SSBSBF #
#
** SSBSBF - STORE BITFIELD IN A TABLE.
*
* D. G. DEPEW. 81/10/26.
*
* PROC SSBSBF (TABLE, ORD, BIT, LEN, SOURCE)
*
* ENTRY TABLE = ARRAY INTO WHICH DATA IS TO BE STORED.
* ORD = WORD ORDINAL WITHIN TABLE WHERE BITFIELD STARTS.
* BIT = STARTING BIT POSITION WITHIN THE WORD (SYMPLESE).
* LEN = NUMBER OF BITS TO STORE (RANGE: 1 TO 60).
* SOURCE = DATA TO BE STORED, RIGHT JUSTIFIED IN A CM WORD.
*
* EXIT TABLE = THE SPECIFIED BITFIELD CONTAINS THE RIGHTMOST
* *LEN* BITS OF *SOURCE*. THE RIGHTMOST BIT OF
* *SOURCE* ALIGNS WITH THE RIGHTMOST BIT OF THE
* BITFIELD, EVEN IF A WORD BOUNDARY IS SPANNED.
* ORD = INCREMENTED BY 1 IF THE BITFIELD SPANS A WORD
* BOUNDARY.
* BIT = FIRST BIT POSITION AFTER THE STORED BITFIELD.
* LEN = UNCHANGED.
* SOURCE = UNCHANGED.
*
* NOTES RESULT IS UNPREDICTABLE IF LEN IS OUT OF RANGE.
* IF THE SPECIFIED BITFIELD SPANS A WORD BOUNDARY, THE
* OVERFLOW BITS ARE STORED INTO THE NEXT CONSECUTIVE CM
* WORD. THAT IS, NO CONSIDERATION IS MADE FOR SYMPL
* PARALLEL ARRAYS OR FOR ARRAYS WITH AN ENTRY SIZE
* GREATER THAN ONE.
#
ARRAY TABLE [00:00] S(1); #TABLE CONTAINING BITFIELD #
ITEM T$WD U(00,00,60);
ITEM ORD; #WORD WITHIN TABLE #
ITEM BIT; #STARTING BIT WITHIN WORD #
ITEM LEN; #LENGTH OF BITFIELD #
ITEM SOURCE U; #WORD THAT CONTAINS DATA #
ITEM THIS; #NUM OF BITS TO STORE IN SPECIFIED WORD #
ITEM NEXT; #NUM OF BITS TO STORE IN FOLLOWING WORD #
IF (BIT + LEN) GR 60
THEN # WORD BOUNDARY IS SPANNED #
BEGIN
THIS = 60 - BIT;
NEXT = BIT + LEN - 60;
B<BIT,THIS> T$WD[ORD] = SOURCE / 2 ** NEXT;
B<0,NEXT> T$WD[ORD + 1] = SOURCE;
ORD = ORD + 1;
BIT = NEXT;
END
ELSE # WORD BOUNDARY NOT SPANNED #
BEGIN
B<BIT,LEN> T$WD[ORD] = SOURCE;
IF (BIT + LEN) EQ 60
THEN # BITFIELD ENDS ON WORD BOUNDARY #
BEGIN
ORD = ORD + 1;
BIT = 0;
END
ELSE # SIMPLEST CASE #
BIT = BIT + LEN;
END
END # SSBSBF #
TERM