SPL to HP C/XL Migration Guide (30231-90001)

B-2
HP C/XL BDEPOSIT Function: Bit Deposit
/**************************************************************
BDEPOSIT SPL BIT DEPOSIT
This emulates the SPL bit deposit operation, for example,
I.(5:6) := J + K;
Using this function, this may be converted to HP C with:
BDEPOSIT(&i,5,6,j+k);
The parameters used by BDEPOSIT are:
dw -- The address of the destination word.
sb -- The starting bit of the deposit field.
nb -- The number of bits to deposit.
exp -- The expression to deposit into the field specified.
***************************************************************/
void BDEPOSIT(dw,sb,nb,exp)
unsigned short *dw, sb, nb, exp;
{
unsigned short m;
nb = 16-nb;
sb = nb-sb;
m = (0xFFFF>>nb)<<sb;
*dw = (*dw & ~m) | (exp<<sb & m);
}
HP C/XL BEXTRACT Macro and Function: Bit Extraction
/*************************************************************
BEXTRACT SPL Bit Extraction
This macro and function perform the SPL bit extraction:
x := y.(10:4);
which may be replaced in HP C by:
x = BEXTRACT(y,10,4);
The parameters to BEXTRACT are:
wd -- The word (unsigned short int) from which to extract bits.
sb -- Starting bit of field (0 through 15, left to right).
nb -- Number of bits in field.
The return value will be the extracted field, right
justified in a 16 bit (unsigned short int) word.
**************************************************************/
#define BEXTRACT(w,s,n) (((unsigned short int)((w)<<(s)))>>(16-(n)))
/*************************************************************/
unsigned short int BEXTRACT(sw,sb,nb)
unsigned short int sw, sb, nb;
{
return((unsigned short int)((sw<<sb))>>(16-nb));
}