(*
    Title: 	Fields - Definitions
    LastEdit:	"Thu May 17 17:54:07 1984"
    Author: 	Mick Jordan
		Cambridge University Computer Laboratory

    Bit field insertion/extraction on CARDINALS.
    The bits are numbered from 0 to BITSPERWORD-1
    where 0 is the least significant bit of the word.
*)

DEFINITION MODULE Fields;
FROM SYSTEMTYPES IMPORT BYTE, SHORT;

EXPORT QUALIFIED 
    Extract, ExtractByte, ExtractShort,
    Insert, InsertByte, InsertShort;

PROCEDURE Extract(v: CARDINAL; low, high: CARDINAL): CARDINAL;
(*  extract bits 'low' to 'high' from 'v'
*)
PROCEDURE Insert(VAR v: CARDINAL; low, high, field: CARDINAL);
(*  insert 'field' in bit positions 'low' to 'high' in 'v'.
*)
PROCEDURE ExtractByte(VAR v: CARDINAL; byteno: CARDINAL): BYTE;
(*  get byte 'byteno', 0=ls byte, 3=ms byte
*)
PROCEDURE ExtractShort(VAR v: CARDINAL; shortno: CARDINAL): SHORT;
(*  get short 'shortno', 0=ls short, 1=ms short
*)
PROCEDURE InsertByte(VAR v: CARDINAL; byteno: CARDINAL; value: BYTE);
(*  byte insertion as per ExtractByte
*)
PROCEDURE InsertShort(VAR v: CARDINAL; shortno: CARDINAL; value: SHORT);
(*  short insertion as per ExtractShort
*)

END Fields.
