Press enter to see results or esc to cancel.

Calculating Offsets of Variables

This procedure calculates offset in data segment for each block of typed constants and variables and checks total data size.

Procedure CalculateVariableOffsetsAndTotalDataSize;
Var DataSegmentOffset: LongRec;

  Procedure CalculateOffsetsOfVariables (Block: TSymbolTable);
  Var ConstOrVarBlock: PConstVarBlockRecord;
      ConstOrVarBlockRec: PtrRec absolute ConstOrVarBlock;
  begin
    UnitPtrRec.Seg := LastLoadedUsedUnit;
    Repeat
      ConstOrVarBlock := Ptr (UnitPtrRec.Seg, UnitPtr^.BlockOffset [Block]);
      While ConstOrVarBlockRec.Ofs <> UnitPtr^.BlockOffset [Succ (Block)] do
        begin
          If ConstOrVarBlock^.Offset <> BlockUnused then
            begin
              ConstOrVarBlock^.Offset := DataSegmentOffset.WordL;
              Inc (DataSegmentOffset.Long, ConstOrVarBlock^.Size);
              If DataSegmentOffset.WordH <> 0 then Error (DataSegmentTooLarge);
            end;
          Inc (ConstOrVarBlock);
        end;
      UnitPtrRec.Seg := UnitPtr^.PreviousUnitSegment;
    until UnitPtrRec.Seg = 0;
  end;

begin
  DataSegmentOffset.Long := 2;
  CalculateOffsetsOfVariables (stTypedConstantsBlocks);
  OffsetOfVariables := DataSegmentOffset.WordL;
  CalculateOffsetsOfVariables (stVariablesBlocks);
  DataBytes := DataSegmentOffset.WordL;
  If DataSegmentOffset.WordL > $FFF0 then Error (DataSegmentTooLarge);
end;