Press enter to see results or esc to cancel.

System Functions Lo, Hi, Swap and Pi

These procedures process system functions Lo, Hi, Swap and Pi.

Procedure Func_Lo; Far;
begin
  Expression^.ExpectIntegerExpressionInParentheses;
  With Expression^ do If Location = elMemory then Include (LocationData.Flags, efSegment);
  Expression^.ExtendInteger ([itUnsigned]);
end;

Procedure Func_Hi; Far;
begin
  Expression^.ExpectIntegerExpressionInParentheses;
  If Expression^.Location = elConstant then
    begin
      Expression^.CheckOrdinalOverflowAndStore (Hi (Expression^.Value.Word), False);
      Exit;
    end;
  With Expression^ do If Location = elMemory then Include (LocationData.Flags, efSegment);
  Expression^.ExtendInteger ([itUnsigned, it16Bit]);
  If Expression^.Location = elMemory then
    begin
      Inc (Expression^.Value.Offset);
      Expression^.DataType := [itUnsigned];
      Exit;
    end;
  Expression^.Calculate;
  Expression^.LoadExpressionToRegisters (urAX);
  GenerateInstruction_TwoBytes ($88, $E0);    { MOV   AL, AH }
  Expression^.EndIntermediateCodeSubroutine;;
  Expression^.DataType := [itUnsigned];
end;

Procedure Func_Swap; Far;
begin
  Expression^.ExpectIntegerExpressionInParentheses;
  If Expression^.Location = elConstant then
    begin
      Expression^.CheckOrdinalOverflowAndStore (Swap (Expression^.Value.Word), False);
      Exit;
    end;
  Expression^.ExtendInteger ([itUnsigned, it16Bit]);
  Expression^.Calculate;
  Expression^.LoadExpressionToRegisters (urAX);
  GenerateInstruction_TwoBytes ($86, $C4);    { XCHG  AH, AL }
  Expression^.EndIntermediateCodeSubroutine;
end;

Procedure Func_Pi; Far;
begin
  With Expression^ do
    begin
      Value.Extended := Pi;
      IntermediateCodeOffset := 0;
      Location := elConstant;
      DataType := [itUnsigned];
      UsedRegisters := [];
      TypeDefPtr := Ptr (SystemUnitSegment, Extended_TypeOffset);
    end;
end;