コード例 #1
0
        /// <summary>
        /// Handles the arithmetic instruction.
        /// </summary>
        private bool HandleArithmeticInstruction()
        {
            try
            {
                Alu.Execute(registers[currentInstruction.ParameterOne.Register],
                            registers[currentInstruction.ParameterTwo.Register],
                            currentInstruction.Type);

                registers['A'] = Alu.R;
            }
            catch
            {
                return(false);
            }

            return(true);
        }
コード例 #2
0
        public void TestADD()
        {
            alu.X = "01000000".BinToByte();
            alu.Y = "00000001".BinToByte();
            alu.Execute(Alu.Cmd.ADD, true);
            Assert.AreEqual("01000001".BinToByte(), alu.Res);
            Assert.AreEqual(false, processor.S);
            Assert.AreEqual(false, processor.O);
            Assert.AreEqual(false, processor.Z);

            alu.X = "10000001".BinToByte();
            alu.Y = "01111111".BinToByte();
            alu.Execute(Alu.Cmd.ADD, true);

            Assert.AreEqual("00000000".BinToByte(), alu.Res);
            Assert.AreEqual(false, processor.S);
            Assert.AreEqual(false, processor.O);
            Assert.AreEqual(true, processor.Z);

            alu.X = "01111111".BinToByte();
            alu.Y = "00000001".BinToByte();
            alu.Execute(Alu.Cmd.ADD, true);
            Assert.AreEqual("10000000".BinToByte(), alu.Res);
            Assert.AreEqual(true, processor.S);
            Assert.AreEqual(true, processor.O);
            Assert.AreEqual(false, processor.Z);

            alu.X = "10000000".BinToByte();
            alu.Y = "11111111".BinToByte();
            alu.Execute(Alu.Cmd.ADD, true);
            Assert.AreEqual("01111111".BinToByte(), alu.Res);
            Assert.AreEqual(false, processor.S);
            Assert.AreEqual(true, processor.O);
            Assert.AreEqual(false, processor.Z);
        }