Exemple #1
0
        public void TestMethod2()
        {
            var processor   = new CpuProcessor();
            var state       = new CpuThreadState(processor);
            var interpreter = new CpuInterpreter(state);

            state.Gpr2 = 3;
            state.Gpr3 = 7;
            interpreter.Interpret(MipsAssembler.StaticAssembleInstructions(@"add r1, r2, r3").Instructions[0]);
            Assert.Equal(3 + 7, (int)state.Gpr1);
        }
        public void TestMethod1()
        {
            var cpuProcessor = CpuUtils.CreateCpuProcessor();

            var dynarecFunction = cpuProcessor.DynarecFunctionCompiler.CreateFunction(
                new InstructionArrayReader(MipsAssembler.StaticAssembleInstructions(@"
					addi r1, r1, 1
					jr r31
					nop
				"                ).Instructions),
                0, checkValidAddress: false
                );

            var cpuThreadState = new CpuThreadState(cpuProcessor);

            Assert.Equal(0, cpuThreadState.Gpr[1]);
            dynarecFunction.Delegate(cpuThreadState);
            Assert.Equal(1, cpuThreadState.Gpr[1]);
        }
        public void DisassembleJumpInstruction()
        {
            var assemblerResult = MipsAssembler.StaticAssembleInstructions(@"
			label1:
				j label2
			label2:
				j label1
				nop
			"            );

            Assert.Equal((uint)4, assemblerResult.Labels["label2"]);
            Assert.Equal((uint)0, assemblerResult.Labels["label1"]);

            Assert.Equal(@"j 0x00000004",
                         new MipsDisassembler().Disassemble(pc: 0 * 4, instruction: assemblerResult.Instructions[0]).ToString());
            Assert.Equal(@"j 0x00000000",
                         new MipsDisassembler().Disassemble(pc: 1 * 4, instruction: assemblerResult.Instructions[1]).ToString());
            Assert.Equal(@"and r0, r0, r0",
                         new MipsDisassembler().Disassemble(pc: 2 * 4, instruction: assemblerResult.Instructions[2]).ToString());
        }