Press enter to see results or esc to cancel.

System Function Sqr

This procedure processes system function Sqr. It generates code to multiply the expression with itself.

Procedure Func_Sqr; Far;
Var CommonType: TIntegerTypeSet;
begin
  Expression^.ExpectIntegerOrFloatingPointExpressionInParentheses;
  With Expression^ do
    begin
      If TypeDefPtr^.BaseType = btInteger then
        begin
          SetLowestCommonIntegerType ([itSigned, it16Bit], DataType, CommonType);
          Expression^.ExtendInteger (CommonType);
          If it32Bit in DataType then
            begin
              Expression^.Calculate;
              Expression^.LoadExpressionToRegisters (urAX);
              GenerateInstruction_TwoBytes ($89, $C1);         { MOV   CX, AX }
              GenerateInstruction_TwoBytes ($89, $D3);         { MOV   BX, DX }
              GenerateInstruction_CALL_FAR (SysProc_LongMul);
              Expression^.EndIntermediateCodeSubroutine;
              UsedRegisters := [urSP, urDX, urAX];
              Exit;
            end;
          Expression^.Calculate;
          Expression^.LoadExpressionToRegisters (urAX);
          GenerateInstruction_TwoBytes ($F7,$E8);             { IMUL  AX }
          GenerateOverflowCheckingCode (Expression^);
          Expression^.EndIntermediateCodeSubroutine;
          Include (UsedRegisters, urDX);
          Exit;
        end;
      If Instructions80x87 in StatementCompilerSwitches then
        begin
          Expression^.ConvertRealToExtended;
          Expression^.LoadExpressionToFPU;
          Expression^.Calculate;
          ModifyAndSroreFPUInstructionForFixup ($C0D9);    { FLD    ST (0)     }
          ModifyAndSroreFPUInstructionForFixup ($C9DE);    { FMULP  ST (1), ST }
          Expression^.EndIntermediateCodeSubroutine;
        end else begin
                   Expression^.ConvertExtendedToReal;
                   Expression^.Calculate;
                   Expression^.LoadRealExpressionToRegisterSet (rAX_BX_DX);
                   GenerateInstruction_CALL_FAR (SysProc_RSqr);
                   Expression^.EndIntermediateCodeSubroutine;
                 end;
    end;
end;