Port Statement

This procedure processes Port and PortW statements. This stetement accesses I/O address space and generates OUT instruction. Reading from Port and PortW is done at expression processing
Procedure TStatement.ProcessPortStatement;
Var PortAddress, PortData: TExpression;
    OutOpCode: Byte;
begin
  GetNextToken;
  OutOpCode := Byte (CurrentIdentifierDataPtr^) + $E6;  { Port = 0, PortW = 1 => OUT_Address_AX }
  ExpectTokenAndGetNext (Token_LeftBracket);
  PortAddress.ExpectIntegerExpression;
  PortAddress.CheckOrdinalRange (Ptr (SystemUnitSegment, Word_TypeOffset));
  ExpectTokenAndGetNext (Token_RightBracket);
  ExpectTokenAndGetNext (Token_Assignment);
  PortData.ExpectIntegerExpression;
  Case OutOpCode and $01 <> 0 of
    True: PortData.CheckOrdinalRange (Ptr (SystemUnitSegment, Word_TypeOffset));
    else PortData.CheckOrdinalRange (Ptr (SystemUnitSegment, Byte_TypeOffset));
  end;
  If (PortAddress.Location = elConstant) and (PortAddress.Value.Byte1 = 0) then
    begin
      PortData.Calculate;
      PortData.LoadExpressionToRegisters (urAX);
      GenerateInstruction_TwoBytes (OutOpCode, PortAddress.Value.Byte);
    end else begin
               CalculateExpressionsAndLoadLeftTo_rAX_AndRightTo_rDX (PortData, PortAddress);
               GenerateInstruction_Byte (OutOpCode or $08);
             end;

  StatementCode := EndSubroutine;
end;
 
 
 
© 2017 Turbo Pascal | Privacy Policy