Ejemplo n.º 1
0
        public void decode()
        {
            /*************************** SPECIAL CASES ****************************/
            // SWI CASE
            if (Extras.isSWIInstruction(currentInstruction))
            {
                return;
            }

            // MUL CASE
            if (Extras.isMulInstruction(currentInstruction))
            {
                mul_instruct = new Mul(memory, registers, currentInstruction, currentInstAddress);
                mul_instruct.decodeMul();
                return;
            }

            // BX CASE
            if (Extras.isBX(currentInstruction))
            {
                bx_instruct = new Bx(memory, registers, currentInstruction, currentInstAddress);
                bx_instruct.decodeBx();
                return;
            }

            /*************************** NORMAL CASES ******************************/
            // get instruction type
            currentInstructionType = Extras.getNormalInstructionType(currentInstruction);

            // NORMAL CASES: create an instruction according to its type
            // and decode the instruction
            switch (currentInstructionType)
            {
            case 0:     // if Data Processing (00x)
            case 1:     // if Data Processing (00x)
                data_processing_instruct = new DataProcessing(memory, registers, currentInstruction, currentInstAddress);
                data_processing_instruct.decodeDP();
                break;

            case 2:     // if Load/Store (01x)
            case 3:     // if Load/Store (01x)
                load_store_instruct = new LoadAndStore(memory, registers, currentInstruction, currentInstAddress);
                load_store_instruct.decodeLaS();
                break;

            case 4:     // if Load/Store (100) Load/Store Multiple FD variant
                load_store_mul_instruct = new LoadAndStoreMul(memory, registers, currentInstruction, currentInstAddress);
                load_store_mul_instruct.decodeLaSMul();
                break;

            case 5:     // if Branch (101)
                branch_instruct = new Branch(memory, registers, currentInstruction, currentInstAddress);
                branch_instruct.decodeB();
                break;

            default:
                instDisLst.Add("Special Instruction");
                Debug.WriteLine("ERROR in CPU.execute(): Type is Special or Non-valid instruction.");
                Debug.WriteLine("ERROR in CPU.decode(): Type is Special or Non-valid instruction.");
                break;
            }
        }