Пример #1
0
        private void UpdateDisassembly()
        {
            this.ResetDisassembly();
            uint savePC = myComputer.getRegisters().ReadWord(15);
            int  i      = 0;

            //save register 15 in TEMPVAR
            if (myComputer.getStepNum() > 4)
            {
                myComputer.getRegisters().WriteWord(15, savePC - 16);
            }
            else
            {
                myComputer.getRegisters().WriteWord(15, (uint)(savePC - (myComputer.getStepNum() * 4)));
                i = 4 - myComputer.getStepNum();
            }
            //set register 15 4 commands back. (sub 16).
            myComputer.disassembling = true;
            myComputer.getCPU().disassembling = true;
            //set computer.disassembling to true
            //set cpu.disassembling to true

            for (; i < 9; i++)
            {
                myComputer.getCPU().disassembly = "";
                myComputer.step();
                this.disassemblyView.Rows[i].Cells[0].Value = String.Format("{0:X8}", myComputer.getRegisters().ReadWord(15) - 12);
                this.disassemblyView.Rows[i].Cells[1].Value = String.Format("{0:X8}", myComputer.getCPU().unDecodedInstruction);
                this.disassemblyView.Rows[i].Cells[2].Value = myComputer.getCPU().disassembly;

                //stop stepping if swi
                if (myComputer.getCPU().disassembly.Length >= 3 && myComputer.getCPU().disassembly.Substring(0, 3) == "swi")
                {
                    this.disassemblyView.Rows[i].Cells[0].Value = String.Format("{0:X8}", myComputer.getRegisters().ReadWord(15) - 8);
                    break;
                }
            }
            //step through 9 times.
            //grab computer.getregister.readword(15)
            //grab computer.getpcu.undecoded instruction
            //grab computer.getcpu.disassembly after each step.

            this.disassemblyView.Rows[4].DefaultCellStyle.BackColor = Color.LightGray;
            //highlight the 5th row

            myComputer.getRegisters().WriteWord(15, savePC);
            //set register 15 = to TEMPVAR
            myComputer.disassembling = false;
            myComputer.getCPU().disassembling = false;
            //set computer.disassembling to false
        }
Пример #2
0
        //Method:       RunTests
        //Purpose:      tests key methods in the CPU class
        //Variables:    myOptions - Options handle to options to class
        public static void RunTests(Options myOptions)
        {
            myOptions.SetFileName("test1.exe");
            Console.WriteLine("testing CPU...");
            Computer myTestComp = new Computer(myOptions);

            myTestComp.endRun  += new Computer.EventHandler(delegate { });
            myTestComp.putChar += new Computer.EventHandler(delegate { });
            Console.WriteLine("testing Fetch, Decode, and Execute methods...");

            //test MOV register
            myTestComp.getRegisters().WriteWord(5, 0);
            myTestComp.getRegisters().WriteWord(3, 4);
            myTestComp.getCPU().Decode((uint)0xE1A05003); //mov r5, r3
            myTestComp.getCPU().Execute();                //mov r5, r3
            Debug.Assert(myTestComp.getRegisters().ReadWord(5) == 4);

            //test MOV immediate
            myTestComp.getCPU().Decode((uint)0xe3a02030); //mov r2, 48
            myTestComp.getCPU().Execute();                //mov r2, 48
            Debug.Assert(myTestComp.getRegisters().ReadWord(2) == 48);
            Debug.Assert(myTestComp.getCPU().disassembly == "mov r2, #48");

            //test MUL
            myTestComp.getRegisters().WriteWord(4, 2);
            myTestComp.getRegisters().WriteWord(2, 8);
            myTestComp.getCPU().Decode((uint)0xE0020294); //mul r2, r4, r2
            myTestComp.getCPU().Execute();                //mul r2, r4, r2
            Debug.Assert(myTestComp.getRegisters().ReadWord(2) == 16);

            //test SUB
            myTestComp.getRegisters().WriteWord(4, 10);
            myTestComp.getCPU().Decode((uint)0xE2445003); //sub r5, r4, #3
            myTestComp.getCPU().Execute();                //sub r5, r4, #3
            Debug.Assert(myTestComp.getRegisters().ReadWord(5) == 7);

            //test RSB
            myTestComp.getRegisters().WriteWord(4, 10);
            myTestComp.getCPU().Decode((uint)0xE2645003); //rsb r5, r4, #3
            myTestComp.getCPU().Execute();                //rsb r5, r4, #3
            Debug.Assert(myTestComp.getRegisters().ReadWord(5) == 4294967289);

            //test AND
            myTestComp.getRegisters().WriteWord(0, 0xFFFF);
            myTestComp.getCPU().Decode((uint)0xE20020FF); //and r2, r0, #255
            myTestComp.getCPU().Execute();                //and r2, r0, #255
            Debug.Assert(myTestComp.getRegisters().ReadWord(2) == 255);

            //test ORR
            myTestComp.getRegisters().WriteWord(0, 0);
            myTestComp.getCPU().Decode((uint)0xE3802012); //orr r2, r0, #18
            myTestComp.getCPU().Execute();                //orr r2, r0, #18
            Debug.Assert(myTestComp.getRegisters().ReadWord(2) == 18);

            //test EOR
            myTestComp.getRegisters().WriteWord(0, 732);
            myTestComp.getCPU().Decode((uint)0xE2202FB7); // eor r2, r0, #732
            myTestComp.getCPU().Execute();                // eor r2, r0, #732
            Debug.Assert(myTestComp.getRegisters().ReadWord(2) == 0);

            //test LDR
            //E5925000 (LDR r5, r2)
            myTestComp.getRegisters().WriteWord(5, 11);
            myTestComp.getMemory().WriteWord(1, 2462);
            myTestComp.getRegisters().WriteWord(2, 1);
            myTestComp.getCPU().Decode((uint)0xE5925000); //LDR r5, r2
            myTestComp.getCPU().Execute();                //LDR r5, r2
            Debug.Assert(myTestComp.getRegisters().ReadWord(5) == 2462);

            //test STR
            //E5821000 (STR r1, r2)
            myTestComp.getRegisters().WriteWord(1, 2463);
            myTestComp.getRegisters().WriteWord(2, 1);
            myTestComp.getCPU().Decode((uint)0xE5821000); //STR r1, r2
            myTestComp.getCPU().Execute();                //STR r1, r2
            Debug.Assert(myTestComp.getMemory().ReadWord(1) == 2463);


            //test LDM
            //18914001 (ldm r1, {r0, r14} or something..)
            //make r1 = memory address 1
            myTestComp.getRegisters().WriteWord(1, 1);
            myTestComp.getMemory().WriteWord(1, 2400);
            myTestComp.getMemory().WriteWord(5, 2402);
            //so r0 should be 2400 and r14 should be 2402
            myTestComp.getCPU().Decode((uint)0x18914001); //ldm r1, {r1, r15} or something..
            myTestComp.getCPU().Execute();                //ldm r1, {r1, r15} or something..
            Debug.Assert(myTestComp.getRegisters().ReadWord(0) == 2400);
            Debug.Assert(myTestComp.getRegisters().ReadWord(14) == 2402);



            Console.WriteLine("success!");
            myTestComp.FileStreamClose();
        }
Пример #3
0
        //Method:       RunTests
        //Purpose:      tests key methods in the CPU class
        //Variables:    myOptions - Options handle to options to class
        public static void RunTests(Options myOptions)
        {
            myOptions.SetFileName("test1.exe");
            Console.WriteLine("testing CPU...");
            Computer myTestComp = new Computer(myOptions);
            myTestComp.endRun += new Computer.EventHandler(delegate { });
            myTestComp.putChar += new Computer.EventHandler(delegate { });
            Console.WriteLine("testing Fetch, Decode, and Execute methods...");

            //test MOV register
            myTestComp.getRegisters().WriteWord(5, 0);
            myTestComp.getRegisters().WriteWord(3, 4);
            myTestComp.getCPU().Decode((uint)0xE1A05003); //mov r5, r3
            myTestComp.getCPU().Execute(); //mov r5, r3
            Debug.Assert(myTestComp.getRegisters().ReadWord(5) == 4);

            //test MOV immediate
            myTestComp.getCPU().Decode((uint)0xe3a02030); //mov r2, 48
            myTestComp.getCPU().Execute(); //mov r2, 48
            Debug.Assert(myTestComp.getRegisters().ReadWord(2) == 48);
            Debug.Assert(myTestComp.getCPU().disassembly == "mov r2, #48");

            //test MUL
            myTestComp.getRegisters().WriteWord(4, 2);
            myTestComp.getRegisters().WriteWord(2, 8);
            myTestComp.getCPU().Decode((uint)0xE0020294); //mul r2, r4, r2
            myTestComp.getCPU().Execute();  //mul r2, r4, r2
            Debug.Assert(myTestComp.getRegisters().ReadWord(2) == 16);

            //test SUB
            myTestComp.getRegisters().WriteWord(4, 10);
            myTestComp.getCPU().Decode((uint)0xE2445003); //sub r5, r4, #3
            myTestComp.getCPU().Execute();  //sub r5, r4, #3
            Debug.Assert(myTestComp.getRegisters().ReadWord(5) == 7);

            //test RSB
            myTestComp.getRegisters().WriteWord(4, 10);
            myTestComp.getCPU().Decode((uint)0xE2645003); //rsb r5, r4, #3
            myTestComp.getCPU().Execute();  //rsb r5, r4, #3
            Debug.Assert(myTestComp.getRegisters().ReadWord(5) == 4294967289);

            //test AND
            myTestComp.getRegisters().WriteWord(0, 0xFFFF);
            myTestComp.getCPU().Decode((uint)0xE20020FF); //and r2, r0, #255
            myTestComp.getCPU().Execute();  //and r2, r0, #255
            Debug.Assert(myTestComp.getRegisters().ReadWord(2) == 255);

            //test ORR
            myTestComp.getRegisters().WriteWord(0, 0);
            myTestComp.getCPU().Decode((uint)0xE3802012); //orr r2, r0, #18
            myTestComp.getCPU().Execute();  //orr r2, r0, #18
            Debug.Assert(myTestComp.getRegisters().ReadWord(2) == 18);

            //test EOR
            myTestComp.getRegisters().WriteWord(0, 732);
            myTestComp.getCPU().Decode((uint)0xE2202FB7); // eor r2, r0, #732
            myTestComp.getCPU().Execute();  // eor r2, r0, #732
            Debug.Assert(myTestComp.getRegisters().ReadWord(2) == 0);

            //test LDR
            //E5925000 (LDR r5, r2)
            myTestComp.getRegisters().WriteWord(5, 11);
            myTestComp.getMemory().WriteWord(1, 2462);
            myTestComp.getRegisters().WriteWord(2, 1);
            myTestComp.getCPU().Decode((uint)0xE5925000); //LDR r5, r2
            myTestComp.getCPU().Execute();  //LDR r5, r2
            Debug.Assert(myTestComp.getRegisters().ReadWord(5) == 2462);

            //test STR
            //E5821000 (STR r1, r2)
            myTestComp.getRegisters().WriteWord(1, 2463);
            myTestComp.getRegisters().WriteWord(2, 1);
            myTestComp.getCPU().Decode((uint)0xE5821000); //STR r1, r2
            myTestComp.getCPU().Execute();  //STR r1, r2
            Debug.Assert(myTestComp.getMemory().ReadWord(1) == 2463);


            //test LDM
            //18914001 (ldm r1, {r0, r14} or something..)
            //make r1 = memory address 1
            myTestComp.getRegisters().WriteWord(1, 1);
            myTestComp.getMemory().WriteWord(1, 2400);
            myTestComp.getMemory().WriteWord(5, 2402);
            //so r0 should be 2400 and r14 should be 2402
            myTestComp.getCPU().Decode((uint)0x18914001); //ldm r1, {r1, r15} or something..
            myTestComp.getCPU().Execute();  //ldm r1, {r1, r15} or something..
            Debug.Assert(myTestComp.getRegisters().ReadWord(0) == 2400);
            Debug.Assert(myTestComp.getRegisters().ReadWord(14) == 2402);



            Console.WriteLine("success!");
            myTestComp.FileStreamClose();
        }