Ejemplo n.º 1
0
        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]);
            }
        }
Ejemplo n.º 2
0
        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)");
        }
Ejemplo n.º 3
0
        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;
            }
        }