Press enter to see results or esc to cancel.

Processing Not

This procedure performs logical operation NOT. For boolean values it negates the value, for constant integer expressions it negates the value and for other integer expressions it generates code for NOT instruction.

Procedure Process_NOT;
Var TempWord: Word;
begin
  GetNextToken;
  ProcessFactor;
  Case TypeDefPtr^.BaseType of
    btInteger: NOT_Integer;
    btBoolean: begin
            If Location = elConstant then
              begin
                ConvertToBooleanByte;
                Value.Word := Value.Word xor 1;
                Exit;
              end;
            ConvertExpressionToBooleanJump;
            LocationData.JumpIfTrueOpCode := LocationData.JumpIfTrueOpCode xor 1;
            TempWord := Value.LongRec.WordH;
            Value.LongRec.WordH := Value.LongRec.WordL;
            Value.LongRec.WordL := TempWord;
          end;
    else Error (OperandTypesDoNotMatchOperator);
  end;
end;

Procedure TExpression.NOT_Integer;
begin
  If Location = elConstant then
    Value.LongInt := not Value.LongInt else
      begin
        Calculate;
        LoadExpressionToRegisters (urAX);
        If not (it16Bit in DataType) then
          begin
            GenerateInstruction_TwoBytes ($F6, $D0);    { NOT   AL }
            EndIntermediateCodeSubroutine;
            Exit;
          end;
        If not (it32Bit in DataType) then
          begin
            GenerateInstruction_TwoBytes ($F7, $D0);    { NOT   AX }
            EndIntermediateCodeSubroutine;
            Exit;
          end;
        GenerateInstruction_TwoBytes ($F7, $D0);        { NOT   AX }
        GenerateInstruction_TwoBytes ($F7, $D2);        { NOT   DX }
        EndIntermediateCodeSubroutine;
      end;
end;