Example #1
0
        public void executeCMP()
        {
            uint meinKmp = myRegister.ReadWord(rn) - operand2;

            //set N flag
            myMemory.SetFlag(0, (Instructions.getSectionValue(31, 31, meinKmp) == 0 ? false : true));

            //set Z flag
            myMemory.SetFlag(1, (meinKmp == 0 ? true : false));

            //set C flag
            myMemory.SetFlag(2, (operand2 > myRegister.ReadWord(rn) ? false : true));

            //set F flag
            try
            {
                myMemory.SetFlag(3, false);
                int tempRN = (int)myRegister.ReadWord(rn);
                int iop2   = (int)operand2;
                int f      = checked (tempRN - iop2);
            }
            catch (OverflowException e)
            {
                myMemory.SetFlag(3, true);
            }
        }
Example #2
0
 public In_ls_OperandTwo(Registers toRegisters, uint toInstruction)
 {
     instruction = toInstruction;
     myRegisters = toRegisters;
     if (Instructions.getSectionValue(23, 23, instruction) == 0)
     {
         uSign = "-";
     }
 }
Example #3
0
        public override void decode()
        {
            switch (instructionName)
            {
            case "swi":
                disassembly = "swi " + Instructions.getSectionValue(23, 0, instruction);
                break;

            case "mul":
                rd = getSectionValue(19, 16, instruction);
                rs = getSectionValue(11, 8, instruction);
                rm = getSectionValue(3, 0, instruction);
                break;

            default:
                break;
            }
        }
Example #4
0
        public uint getValue()
        {
            type = Instructions.getSectionValue(27, 25, instruction);
            if (type == 2)
            {
                //immediate
                if (Instructions.getSectionValue(11, 0, instruction) != 0)
                {
                    In_LoadStore.opTwoDissasembly = ", #" + uSign + Convert.ToString(Instructions.getSectionValue(11, 0, instruction));
                }
                else
                {
                    In_LoadStore.opTwoDissasembly = "";
                }
                return(Instructions.getSectionValue(11, 0, instruction));
            }
            else if (type == 3)
            {
                //shift

                rm       = Instructions.getSectionValue(3, 0, instruction);
                shift    = Instructions.getSectionValue(6, 5, instruction);
                shiftAmt = Instructions.getSectionValue(11, 7, instruction);

                strShiftAmt = '#' + Convert.ToString(Instructions.getSectionValue(11, 7, instruction));
                In_LoadStore.opTwoDissasembly = ", " + uSign + "r" + Convert.ToString(rm);

                return(getShiftDone());
            }
            else
            {
                //register list
                uint numOfSetBits = 0;
                foreach (bool x in new BitArray(BitConverter.GetBytes(Instructions.getSectionValue(15, 0, instruction))))
                {
                    if (x)
                    {
                        numOfSetBits++;
                    }
                }
                return(numOfSetBits);
            }
        }
Example #5
0
        public uint getValue()
        {
            if (Instructions.getSectionValue(25, 25, instruction) == 1)
            {
                if (Instructions.getSectionValue(11, 8, instruction) == 0)
                {
                    In_DataProcessing.opTwoDissasembly = '#' + Convert.ToString(Instructions.getSectionValue(7, 0, instruction));
                }
                type = 3;
                In_DataProcessing.opTwoDissasembly = '#' + Convert.ToString((Instructions.getSectionValue(7, 0, instruction) >> (int)(2 * Instructions.getSectionValue(11, 8, instruction))) | (Instructions.getSectionValue(7, 0, instruction) << (32 - (int)(2 * Instructions.getSectionValue(11, 8, instruction)))));
                return((Instructions.getSectionValue(7, 0, instruction) >> (int)(2 * Instructions.getSectionValue(11, 8, instruction))) | (Instructions.getSectionValue(7, 0, instruction) << (32 - (int)(2 * Instructions.getSectionValue(11, 8, instruction)))));
            }

            rm    = Instructions.getSectionValue(3, 0, instruction);
            shift = Instructions.getSectionValue(6, 5, instruction);


            //this instruction will be shifting rn by something
            if (rm == 15)
            {
                In_DataProcessing.opTwoDissasembly = "pc";
            }
            else
            {
                In_DataProcessing.opTwoDissasembly = 'r' + Convert.ToString(rm);
            }


            if (Instructions.getSectionValue(4, 4, instruction) == 1)
            {
                type        = 2;
                shiftAmt    = myRegisters.ReadWord(Instructions.getSectionValue(11, 8, instruction));
                strShiftAmt = 'r' + Convert.ToString(Instructions.getSectionValue(11, 8, instruction));
                return(getShiftDone()); //calculate shift
            }
            else
            {
                type        = 1;
                shiftAmt    = Instructions.getSectionValue(11, 7, instruction);
                strShiftAmt = '#' + Convert.ToString(Instructions.getSectionValue(11, 7, instruction));
                return(getShiftDone()); //calculate shift
            }
        }
Example #6
0
        public void executeSTM()
        {
            //rn is a pointer in memory
            //get num of bits set (operand2 = num of bits set)
            //if increment after, start at address in memory rn.
            uint memAddr    = myRegister.ReadWord(rn);
            bool incrAfter  = false;
            bool decrBefore = false;

            //calculate p/u flags
            if (p == 0 && u == 1)
            {
                incrAfter   = true;
                disassembly = "stmia" + Instructions.firstOpcode + " ";
            }
            else if (p == 1 && u == 0)
            {
                decrBefore  = true;
                disassembly = "stmfd" + Instructions.firstOpcode + " ";
            }

            string addresses = "{";

            //do the load
            BitArray myBA = new BitArray(BitConverter.GetBytes(Instructions.getSectionValue(15, 0, instruction)));

            for (uint i = 0; i < 16; i++)
            {
                if (myBA.Get((int)i))
                {
                    addresses += "r" + i + ", ";
                    if (incrAfter && !disassembling)
                    {
                        myMemory.WriteWord(memAddr, myRegister.ReadWord(i));
                        memAddr += 4;
                    }
                    else if (decrBefore && !disassembling)
                    {
                        myMemory.WriteWord(memAddr - (operand2 * 4), myRegister.ReadWord(i));
                        memAddr += 4;
                    }
                }
            }
            addresses  = addresses.Remove(addresses.Length - 2);
            addresses += "}";
            if (rn == 13)
            {
                disassembly += "sp";
            }
            else
            {
                disassembly += "r" + rn;
            }

            //do the writeBack
            if (decrBefore && w == 1)
            {
                if (!disassembling)
                {
                    myRegister.WriteWord(rn, myRegister.ReadWord(rn) - (operand2 * 4));
                }
                disassembly += "!";
            }
            if (incrAfter && w == 1)
            {
                if (!disassembling)
                {
                    myRegister.WriteWord(rn, myRegister.ReadWord(rn) + (operand2 * 4));
                }
                disassembly += "!";
            }

            disassembly += ", " + addresses;
        }