示例#1
0
        /*******************************************************************************
         ***                      OBJPTONE function                                   ***
         ********************************************************************************
         *** DESCRIPTION: This function handles the first three digits of the Object  ***
         *** code.                                                                    ***
         ********************************************************************************
         *** INPUT ARGS: string op, NIXBPE bits                                       ***
         *** OUTPUT ARGS: N/A                                                         ***
         *** IN/OUT ARGS: N/A                                                         ***
         *** RETURN: First three digits of the object code                            ***
         ********************************************************************************/

        public string ObjPtOne(string op, NIXBPE bits)
        {
            int N = 0, I = 0, X = 0, B = 0, P = 0, E = 0;

            if (bits.n == true)
            {
                N = 32;
            }
            if (bits.i == true)
            {
                I = 16;
            }
            if (bits.x == true)
            {
                X = 8;
            }
            if (bits.b == true)
            {
                B = 4;
            }
            if (bits.p == true)
            {
                P = 2;
            }
            if (bits.e == true)
            {
                E = 1;
            }

            return((int.Parse(op.PadRight(3, '0'), System.Globalization.NumberStyles.HexNumber) + (N + I + X + B + P + E)).ToString("X").PadLeft(3, '0'));
        }
示例#2
0
        /*******************************************************************************
         ***                      setNIXBPE function                                  ***
         ********************************************************************************
         *** DESCRIPTION: This function takes in line and outputs the bits            ***
         ********************************************************************************
         *** INPUT ARGS: Node_Sym table, string opt, string opd, bool b               ***
         *** OUTPUT ARGS: N/A                                                         ***
         *** IN/OUT ARGS: N/A                                                         ***
         *** RETURN: NIXBPE bit                                                       ***
         ********************************************************************************/

        public NIXBPE setNIXBPE(Node_Sym table, string opt, string opd, bool b)
        {
            NIXBPE      bit = new NIXBPE();
            Expressions ex  = new Expressions();

            if (opt[0] == '+')
            {
                bit.e = true;
            }
            else if (b == true)
            {
                bit.b = true;
            }
            else
            {
                bit.p = true;
            }

            bit.n = ex.insert(table, opd).N_bit;
            bit.i = ex.insert(table, opd).I_bit;
            bit.x = ex.insert(table, opd).X_bit;

            return(bit);
        }
示例#3
0
        /*******************************************************************************
         ***                      PASSDUO function                                    ***
         ********************************************************************************
         *** DESCRIPTION: This Pass 2 funciton takes in information from the .tmp     ***
         *** file and outputs the Object Code for each line that applies, and then    ***
         *** creates the object program to the assembly code that was given intially. ***
         ********************************************************************************
         *** INPUT ARGS: List<Node_Op> ops, Node_Sym table, Node_Lit lit, string file ***
         *** OUTPUT ARGS: N/A                                                         ***
         *** IN/OUT ARGS: N/A                                                         ***
         *** RETURN: Node_P2 p2                                                       ***
         ********************************************************************************/

        public Node_P2 PassDuo(List <Node_Op> ops, Node_Sym table, Node_Lit lit, string file)
        {
            Node_P2   p2     = new Node_P2();
            Node_Op   op     = new Node_Op();
            NIXBPE    nixbpe = new NIXBPE();
            Node_Sym  sym    = new Node_Sym();
            Node_Exp  ex     = new Node_Exp();
            Registers reg    = new Registers();

            Literal_Table litTab = new Literal_Table();
            Expressions   Exp    = new Expressions();
            OpCodes       opCode = new OpCodes();
            Symbol_Table  syTab  = new Symbol_Table();
            List <string> codes  = new List <string>();
            List <string> mrec   = new List <string>();

            string[] Prog = File.ReadAllLines(file);

            int    lnum;
            string counter;
            string label = null;
            string operation;
            string operand    = null;
            string rrec       = null;
            string drec       = null;
            string prog_len   = "00000";
            string prog_start = "00000";
            string prog_name  = "00000";

            string Obj_Code = null;

            string[] splitLine;
            string   tmpStr;
            string   tmpFmt     = null;
            bool     Base_bit   = false;
            string   Base_Label = null;

            foreach (string line in Prog)
            {
                splitLine = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                if (splitLine.Length != 1)
                {
                    //SETS LINE NUMBER
                    if (Int32.TryParse(splitLine[0], out lnum))
                    {
                    }
                    ;

                    //SETS LOAD COUNTER
                    counter = splitLine[1];

                    //SETS LABEL
                    if (splitLine.Length == 5)
                    {
                        label     = splitLine[2].ToUpper();
                        splitLine = splitLine.Where(w => w != splitLine[0]).ToArray();
                    }
                    else
                    {
                        tmpStr = splitLine[2];
                        if (tmpStr[0] != '+' && opCode.search(ops, tmpStr) == null)
                        {
                            label     = tmpStr.ToUpper();
                            splitLine = splitLine.Where(w => w != splitLine[2]).ToArray();
                        }
                    }

                    //SETS OPERATION
                    operation = splitLine[2].ToUpper();

                    //SETS OPERAND
                    if (splitLine.Length > 3)
                    {
                        operand = splitLine[3];
                    }

                    if (label == Base_Label && int.Parse(counter, System.Globalization.NumberStyles.HexNumber) > int.Parse("7FF", System.Globalization.NumberStyles.HexNumber))
                    {
                        syTab.search(table, label).value = SubHex(counter, "7FF").TrimStart('0').PadLeft(5, '0');
                    }
                    else
                    {
                        if (operation == "START")
                        {
                            prog_start = splitLine[3]; //FOR THE HEADER
                            prog_name  = label;        //FOR THE HEADER
                        }
                        else if (operation != "END")
                        {
                            //FORMAT 4 CHECK
                            if (operation[0] != '+')
                            {
                                op = opCode.search(ops, operation);
                            }
                            else
                            {
                                tmpStr = operation.TrimStart('+');
                                op     = opCode.search(ops, tmpStr);
                                tmpFmt = "4";
                            }

                            if (op == null)
                            {
                                if (operation == "BASE")
                                {
                                    Base_Label = operand;
                                }
                                else if (operation == "BYTE")
                                {
                                    if (operand[0] == 'X')
                                    {
                                        Obj_Code = operand.TrimStart('X', '\'').TrimEnd('\'').PadLeft(6, '0');
                                    }
                                    else
                                    {
                                        Obj_Code = BitConverter.ToString(Encoding.Default.GetBytes(operand.TrimStart('\'', 'C', 'c').TrimEnd('\''))).Replace("-", "").PadLeft(6, '0');
                                    }
                                }
                                else if (operation == "EQU")
                                {
                                }
                                else if (operation == "EXTDEF")
                                {
                                    foreach (string n in operand.Split(','))
                                    {
                                        drec = drec + "^" + n + "^" + syTab.search(table, TrimOp(n)).value;
                                    }
                                }
                                else if (operation == "EXTREF")
                                {
                                    foreach (string n in operand.Split(','))
                                    {
                                        rrec = rrec + "^" + n;
                                    }
                                }
                                else if (operation == "RESB")
                                {
                                }
                                else if (operation == "RESW")
                                {
                                }
                                else if (operation == "WORD")
                                {
                                    Obj_Code = int.Parse(operand, System.Globalization.NumberStyles.HexNumber).ToString("X").PadLeft(6, '0');
                                    if (operand.Contains('+') || operand.Contains('-'))
                                    {
                                        mrec.Add("M^" + AddHex(counter.PadLeft(6, '0'), "1") + "^06^");
                                    }
                                }
                            }
                            else if (tmpFmt != null)
                            {
                                nixbpe = setNIXBPE(table, operation, operand, Base_bit);
                                if (operand[0] == '#')
                                {
                                    Obj_Code = ObjPtOne(op.code, nixbpe) + counter;
                                }
                                else if (operand[0] == '@')
                                {
                                    Obj_Code = ObjPtOne(op.code, nixbpe) + Exp.insert(table, operand).value;
                                }
                                else
                                {
                                    Obj_Code = ObjPtOne(op.code, nixbpe) + Exp.insert(table, operand).value;
                                }
                                mrec.Add("M^" + AddHex(counter, "1").PadLeft(6, '0') + "^05^+" + operand.TrimStart('@', '#').TrimEnd(',', 'X'));
                            }
                            else
                            {
                                if (op.format == "1")
                                {
                                    Obj_Code = op.code;
                                }
                                else if (op.format == "2")
                                {
                                    Obj_Code = op.code + fmt2(operand);
                                }
                                else if (op.format == "3")
                                {
                                    nixbpe = setNIXBPE(table, operation, operand, Base_bit);
                                    if (nixbpe.n == true && nixbpe.i == false && nixbpe.x == false)  //IF INDIRECT '@'
                                    {
                                        Obj_Code = ObjPtOne(op.code, nixbpe) + SubHex(Exp.insert(table, operand).value, getNext(op, counter)).TrimStart('0').PadLeft(3, '0');
                                    }
                                    else if (nixbpe.n == false && nixbpe.i == true && nixbpe.x == false)  //IF IMMEDIATE '#'
                                    {
                                        Obj_Code = ObjPtOne(op.code, nixbpe) + Exp.insert(table, operand).value.TrimStart('0').PadLeft(3, '0');
                                    }
                                    else if (nixbpe.n == false && nixbpe.i == false && nixbpe.x == true)  //IF INDEXED ',X'
                                    {
                                        Obj_Code = ObjPtOne(op.code, nixbpe) + SubHex(Exp.insert(table, operand).value, getNext(op, counter)).TrimStart('0').PadLeft(3, '0');
                                    }
                                    else
                                    {
                                        if (operand[0] == '=')
                                        {
                                            Obj_Code = ObjPtOne(op.code, nixbpe) + SubHex(litTab.search(lit, operand).address, getNext(op, counter)).TrimStart('0').PadLeft(3, '0');
                                        }
                                        else
                                        {
                                            Obj_Code = ObjPtOne(op.code, nixbpe) + SubHex(Exp.insert(table, operand).value, getNext(op, counter)).TrimStart('0').PadLeft(3, '0');
                                        }
                                    }
                                }
                            }
                        }
                    }

                    if (operation == "*")
                    {
                        Obj_Code = litTab.search(lit, operand).value;
                    }
                }
                else
                {
                    prog_len = splitLine[0];
                }

                //ADD THE OBJ CODE TO THE P2 NODE
                if (splitLine.Length != 1)
                {
                    p2.prog.Add(line + string.Format("{0,-10}", Obj_Code));
                }

                if (Obj_Code != null)
                {
                    codes.Add(Obj_Code);
                }

                //SET VARIABLES BACK TO NULL
                tmpFmt   = null;
                tmpStr   = null;
                label    = null;
                Obj_Code = null;
            }

            p2.obj_prog.Add("H^" + prog_name + "^" + prog_start.PadLeft(5, '0') + "^" + prog_len.PadLeft(5, '0'));
            if (drec != null)
            {
                p2.obj_prog.Add("D" + drec);
            }
            if (rrec != null)
            {
                p2.obj_prog.Add("R" + rrec);
            }
            p2.obj_prog = T_Records(p2.obj_prog, codes);
            foreach (string m in mrec)
            {
                p2.obj_prog.Add(m);
            }
            p2.obj_prog.Add("E^" + prog_start.PadLeft(6, '0'));
            return(p2);
        }