//============================ // Methods //============================ //MC Loaders public void loadMC_fromMem() { //Assuming there is only ONE program in the memory //It reads the .text address by address and loads //each address until it reaches InstructionCounter. (no instructions after that) //first check if instructionCounter !=0 if (Mem.instructionCounter != 0) { for (int i = 0; i < Mem.instructionCounter * 4; i = i + 4) { MachineCodes.Add(Mem.loadInstruction(i)); } } else { FailedToLoadMC.Invoke("loadMC_fromMem::Disassembler", "NO INSTRUCTIONS FOUND IN MEMORY", "Dear User, please ... assemble first or something... or load from file!"); } }
//Cycles public void fetch() { //First Get the instruction from the address of the pc counter. //Since the memory can load directly without the need of the full address, //Calculate the offset int offset = PC - 4194304; //Now fetch; IR = Mem.loadInstruction(offset); //First check if IR =0 int IR_int = Convert.ToInt32(IR, 2); if (IR_int == 0) { //Now check if Clock == 0; if (clock == 0) { running = false; EmptyInstructions.Invoke(); } else { running = false; Terminate_Dropped.Invoke("Program Dropped...\n"); } } else { running = true; //Now increment the PC; PC += 4; //by one because LoadInstruction handles the stuff.. ;) Fetched.Invoke(); } }