More than one reader has contacted me requesting a copy of the "will it fit"
macro. It's pretty simple, as follows:
MACRO
&LABEL WIF &P=1,&L=,&C=,&S=0,&OK=,&NFG=
.*
.* Will It Fit?
.*
.* Given the following:
.* 1. Register "P" pointing to the next available location in an
.* integral buffer (i.e., the size and alignment are a power of
.* two);
.* 2. Register "L" containing the length of a prospective object to
.* be added to the buffer; and
.* 3. Characteristic C, where C represents the integral boundary as
.* a power of two;
.* Will the prospective object fit within the buffer?
.*
.* Operands:
.* P: Starting address; default is general register 1.
.* L: Length of object in a general register; no default.
.* C: Characteristic (i.e., power of two) representing the
.* integral boundary (e.g., C=8 means a 256-byte boundary).
.* S: Scratch register; default is general register 0.
.* OK: Branch location if the object fits; no default.
.* NFG: Branch location if the object does not fit; no default.
.*
.* A PSW condittion code of zero indicates the object fits, and may be
.* used in place of the OK and/or NFG operands.
.*
AIF (&C GT 64).BAD_C
&LABEL LAY &S,-1(&A,&P) Point at last prospective byte.
RXSBGT &S,&P,0,63-&C,0 Carry past boundary?
AIF ('&OK' EQ '').SKIP_OK
JZ &OK No; prospective object fits.
.SKIP_OK ANOP
AIF ('&NFG' EQ '').SKIP_NFG
JNZ &NFG Yes; prospective object doesn't fit.
.SKIP_NFG MEND
.BAD_C MNOTE 8,'C must be between 0 and 63.'
MEND