コード例 #1
0
ファイル: SemanticAnalysis.cs プロジェクト: javorbg/Compiler
        public void GenerateObejctiveCode()
        {
            for (int i = 0; i < MF.Count; i++)
            {
                GenerateOperation(MF[i], i);
            }

            ObjectiveCode.Add("    MOV	AH,0");
            ObjectiveCode.Add("    INT	16H");
            ObjectiveCode.Add("    INT	20H");

            GenerateMemory();



            string[] temp = File.ReadAllLines("in.asm");

            for (int i = 0; i < temp.Length; i++)
            {
                ObjectiveCode.Add(temp[i]);
            }
            temp = File.ReadAllLines("out.asm");

            for (int i = 0; i < temp.Length; i++)
            {
                ObjectiveCode.Add(temp[i]);
            }
        }
コード例 #2
0
ファイル: SemanticAnalysis.cs プロジェクト: javorbg/Compiler
        public void GenerateMemory()
        {
            bool   first = false;
            string line  = "";

            foreach (var item in MainTable)
            {
                if (item.Code == 24)
                {
                    if (first)
                    {
                        Variable.Add(item);
                        line = item.Name.ToUpper() + "    DW  ";// + item.Addrres.ToString();
                        ObjectiveCode.Add(line);
                    }
                    first = true;
                }
            }


            ObjectiveCode.Add("TABLE	DB	'0123456789ABCDEF'");
            ObjectiveCode.Add("BUFER	DB  DUP(0)");
            ObjectiveCode.Add("BUF1	DB  DUP(0)");
        }
コード例 #3
0
ファイル: SemanticAnalysis.cs プロジェクト: javorbg/Compiler
        public void GenerateOperation(TransformForm operation, int i)
        {
            string line;

            switch (operation.Operation)
            {
            case "*":
            {
                line = "    MOV    AX," + MainTable[operation.Operand1].Name.ToUpper();
                ObjectiveCode.Add(line);
                line = "    MUL    AX," + MainTable[operation.Operand2].Name.ToUpper();
                ObjectiveCode.Add(line);
                line = "    MOV  " + MainTable[operation.Result].Name.ToUpper() + ",AX";
                ObjectiveCode.Add(line);
            }
            break;

            case "/":
            {
                line = "    MOV    AX," + MainTable[operation.Operand1].Name.ToUpper();
                ObjectiveCode.Add(line);
                line = "    DIV    AX," + MainTable[operation.Operand2].Name.ToUpper();
                ObjectiveCode.Add(line);
                line = "    MOV  " + MainTable[operation.Result].Name.ToUpper() + ",AX";
                ObjectiveCode.Add(line);
            }
            break;

            case "+":
            {
                line = "    MOV    AX," + MainTable[operation.Operand1].Name.ToUpper();
                ObjectiveCode.Add(line);
                line = "    ADD    AX," + MainTable[operation.Operand2].Name.ToUpper();
                ObjectiveCode.Add(line);
                line = "    MOV  " + MainTable[operation.Result].Name.ToUpper() + ",AX";
                ObjectiveCode.Add(line);
            }
            break;

            case "-":
            {
                line = "    MOV    AX," + MainTable[operation.Operand1].Name.ToUpper();
                ObjectiveCode.Add(line);
                line = "    SUB    AX," + MainTable[operation.Operand2].Name.ToUpper();
                ObjectiveCode.Add(line);
                line = "    MOV  " + MainTable[operation.Result].Name.ToUpper() + ",AX";
                ObjectiveCode.Add(line);
            }
            break;

            case ">":
            {
                line = label + i.ToString() + "    MOV    AX," + MainTable[operation.Operand1].Name.ToUpper();
                ObjectiveCode.Add(line);
                line = "    MOV    BX," + MainTable[operation.Operand2].Name.ToUpper();
                ObjectiveCode.Add(line);
                line = "    CMP    AX,BX";
                ObjectiveCode.Add(line);
                line = "    JG " + label + operation.Operand1;
                ObjectiveCode.Add(line);
            }
            break;

            case "<":
            {
                line = label + i.ToString() + "    MOV    AX," + MainTable[operation.Operand1].Name.ToUpper();
                ObjectiveCode.Add(line);
                line = "    MOV    BX," + MainTable[operation.Operand2].Name.ToUpper();
                ObjectiveCode.Add(line);
                line = "    CMP    AX,BX";
                ObjectiveCode.Add(line);
                line = "    JL  " + label + operation.Operand1;
                ObjectiveCode.Add(line);
            }
            break;

            case ">=":
            {
                line = label + i.ToString() + "    MOV    AX," + MainTable[operation.Operand1].Name.ToUpper();
                ObjectiveCode.Add(line);
                line = "    MOV    BX," + MainTable[operation.Operand2].Name.ToUpper();
                ObjectiveCode.Add(line);
                line = "    CMP    AX,BX";
                ObjectiveCode.Add(line);
                line = "    JGE  " + label + operation.Operand1;
                ObjectiveCode.Add(line);
            }
            break;

            case "<=":
            {
                line = label + i.ToString() + "    MOV    AX," + MainTable[operation.Operand1].Name.ToUpper();
                ObjectiveCode.Add(line);
                line = "    MOV    BX," + MainTable[operation.Operand2].Name.ToUpper();
                ObjectiveCode.Add(line);
                line = "    CMP    AX,BX";
                ObjectiveCode.Add(line);
                line = "    JLE   " + label + operation.Operand1;
                ObjectiveCode.Add(line);
            }
            break;

            case "==":
            {
                line = label + i.ToString() + "    MOV    AX," + MainTable[operation.Operand1].Name.ToUpper();
                ObjectiveCode.Add(line);
                line = "    MOV    BX," + MainTable[operation.Operand2].Name.ToUpper();
                ObjectiveCode.Add(line);
                line = "    CMP    AX,BX";
                ObjectiveCode.Add(line);
                line = "    JE   " + label + operation.Operand1;
                ObjectiveCode.Add(line);
            }
            break;

            case "=":
            {
                line = "    MOV AX," + MainTable[Index[operation.Operand1]].Name.ToUpper();
                ObjectiveCode.Add(line);
                line = "    MOV  " + MainTable[operation.Operand2].Name.ToUpper() + ",AX";
                ObjectiveCode.Add(line);
            }
            break;

            case "IN":
            {
                ObjectiveCode.Add("    LEA	SI,BUFER");
                ObjectiveCode.Add("    LEA DI," + MainTable[operation.Operand1].Name.ToUpper());
                ObjectiveCode.Add("    CALL IN_CH");
            }
            break;

            case "OUT":
            {
                ObjectiveCode.Add("    MOV AX," + MainTable[operation.Operand1].Name.ToUpper());
                ObjectiveCode.Add("    MOV  BUF1,AX");
                ObjectiveCode.Add("    CALL PRINTB");
            }
            break;

            case "JMP":
            {
                line = "    JMP " + label + operation.Operand1;
                ObjectiveCode.Add(line);
                line = label + (i).ToString();
                ObjectiveCode.Add(line);
            }
            break;
            }
        }
コード例 #4
0
 public override int GetHashCode() =>
 ObjectiveCode != null?ObjectiveCode.GetHashCode() : 0;