示例#1
0
 private void CopyRegGroup(NSASM super)
 {
     for (int i = 0; i < super.regGroup.Length; i++)
     {
         this.regGroup[i].Copy(super.regGroup[i]);
     }
 }
示例#2
0
        public static string Execute(string code, long group)
        {
            if (code.Length > 512)
            {
                return("嗝");
            }

            string result = "";

            Util.Output = (value) => { result += value; };
            code        = code.Replace(";;", "\n");
            var core = new dotNSASM.NSASM(512, 512, 64, Util.GetSegments(code));

            core.SetGroupID(group);
            Thread thread = new Thread(() => core.Run());
            int    start  = Environment.TickCount;

            thread.Start();
            while (thread.IsAlive)
            {
                if (start - Environment.TickCount > 1000)
                {
                    thread.Abort();
                    result = "已超时 | Time Exceed";
                }
            }
            Util.Output = (value) => { };

            return(result);
        }
示例#3
0
        public static void Execute(string str)
        {
            string path = "local";

            if (str == null)
            {
                return;
            }

            int heap = 64, stack = 32, regs = 16;

            string conf = GetSegment(str, ".<conf>");

            if (conf == null)
            {
                Print("Conf load error.\n");
                Print("At file: " + path + "\n\n");
                return;
            }
            if (conf.Length > 0)
            {
                StringReader confReader = new StringReader(conf);
                try
                {
                    string buf;
                    while (confReader.Peek() != -1)
                    {
                        buf = confReader.ReadLine();
                        switch (buf.Split(' ')[0])
                        {
                        case "heap":
                            heap = int.Parse(buf.Split(' ')[1]);
                            break;

                        case "stack":
                            stack = int.Parse(buf.Split(' ')[1]);
                            break;

                        case "reg":
                            regs = int.Parse(buf.Split(' ')[1]);
                            break;
                        }
                    }
                }
                catch (Exception e)
                {
                    Print("Conf load error.\n");
                    Print("At file: " + path + "\n\n");
                    return;
                }
            }

            string[][] code  = GetSegments(str);
            NSASM      nsasm = new NSASM(heap, stack, regs, code);

            nsasm.Run();
            Print("\nNSASM running finished.\n\n");
        }
示例#4
0
        public static void Interactive()
        {
            Print("Now in console mode.\n\n");
            string buf;
            int    lines = 1; NSASM.Result result;

            string[][] code  = GetSegments("nop\n"); //ld func allowed
            NSASM      nsasm = new NSASM(64, 32, 16, code);

            while (true)
            {
                Print(lines + " >>> ");
                buf = Scan();
                if (buf.Length == 0)
                {
                    lines += 1;
                    continue;
                }
                buf = FormatLine(buf);

                if (buf.Contains("#"))
                {
                    Print("<" + buf + ">\n");
                    continue;
                }
                result = nsasm.Execute(buf);
                if (result == NSASM.Result.ERR)
                {
                    Print("\nNSASM running error!\n");
                    Print("At line " + lines + ": " + buf + "\n\n");
                }
                else if (result == NSASM.Result.ETC)
                {
                    break;
                }
                if (buf.StartsWith("run") || buf.StartsWith("call"))
                {
                    nsasm.Run();
                }

                lines += 1;
            }
        }
示例#5
0
 private NSASM(NSASM super, string[][] code) : this(super.heapSize, super.stackSize, super.regCnt, code)
 {
     CopyRegGroup(super);
 }
示例#6
0
 protected virtual NSASM Instance(NSASM super, string[][] code)
 {
     return(new NSASM(super, code));
 }
示例#7
0
        public static void Binary(string path)
        {
            byte[] data = BinaryInput.Invoke(path);
            if (data.Length < 16)
            {
                return;
            }

            if (GetStr2(data, 0) != "NS")
            {
                return;
            }
            if (GetUint16(data, 2) != 0xFFFF)
            {
                return;
            }

            ushort sum = 0;

            for (int i = 0; i < data.Length - 2; i++)
            {
                sum += data[i];
            }
            if (sum != GetUint16(data, data.Length - 2))
            {
                return;
            }

            ushort heap, stack, regs, segCnt;

            heap   = GetUint16(data, 4);
            stack  = GetUint16(data, 6);
            regs   = GetUint16(data, 8);
            segCnt = GetUint16(data, 10);

            int offset = 12, segPos = -1;

            string[][] code = new string[segCnt][];
            for (int i = 0; i < segCnt; i++)
            {
                code[i] = new string[2];
            }

            const int SEG_NAME = 0, SEG_CODE = 1;
            int       state = SEG_NAME, offmax = data.Length - 1;

            while (offset <= offmax - 4)
            {
                if (GetUint16(data, offset) == 0xA5A5)
                {
                    if (segPos >= segCnt - 1)
                    {
                        return;
                    }
                    segPos         += 1; offset += 2;
                    state           = SEG_NAME;
                    code[segPos][0] = "";
                }
                else if (GetUint16(data, offset) == 0xAAAA)
                {
                    offset         += 2;
                    state           = SEG_CODE;
                    code[segPos][1] = "";
                }
                else
                {
                    if (state == SEG_NAME)
                    {
                        code[segPos][0] += (char)data[offset];
                    }
                    else if (state == SEG_CODE)
                    {
                        code[segPos][1] += (char)data[offset];
                    }
                    offset += 1;
                }
            }

            if (GetUint16(data, offset) != 0xFFFF)
            {
                return;
            }

            NSASM nsasm = new NSASM(heap, stack, regs, code);

            nsasm.Run();
            Print("\nNSASM running finished.\n\n");
        }