//Method: Fetch //Purpose: Reads next word to execute, increments program counter. public uint Fetch() { //retrive command pointed to by addr stored in register 15 uint command = myRegisters.ReadWord(15); return(myMemory.ReadWord(command - 8)); //read word from RAM address specified by program counter register //(program counter register is 15) }
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 } }
public override void execute() { //switch statement to determine WHICH execute command to do. switch (opcode) { case 1: //to string disassembly = "bx" + Instructions.firstOpcode + (myRegister.ReadWord(getSectionValue(3, 0, instruction))); if (!disassembling) { executeBX(); } break; case 10: //to string disassembly = "b" + Instructions.firstOpcode + " " + (myRegister.ReadWord(15) + targetAddr); if (!disassembling) { executeB(); } break; case 11: //to string disassembly = "bl" + Instructions.firstOpcode + " " + (myRegister.ReadWord(15) + targetAddr); if (!disassembling) { executeBL(); } break; default: break; } }
public uint getShiftDone() { rm = myRegisters.ReadWord(rm); switch (shift) { case 0: //LSL if (shiftAmt != 0) { In_LoadStore.opTwoDissasembly += ", lsl " + strShiftAmt; } return(rm << (int)shiftAmt); case 1: //LSR if (shiftAmt != 0) { In_LoadStore.opTwoDissasembly += ", lsr " + strShiftAmt; } return(rm >> (int)shiftAmt); case 2: //ASR //CAST TO INT (logic shift becomes arithmaic) if (shiftAmt != 0) { In_LoadStore.opTwoDissasembly += ", asr " + strShiftAmt; } return((uint)((int)rm >> (int)shiftAmt)); default: //ROR In_LoadStore.opTwoDissasembly += ", ror " + strShiftAmt; return((rm >> (int)shiftAmt) | (rm << (int)(32 - shiftAmt))); } }
//Method: Run //Purpose: Runs through entire simulated program using CPU fetch-decode-execute. public void Run() { uint curCommand = myCPU.Fetch(); while (curCommand != 0 && !abort) { storedBranchPC = 0; stepNum++; //used for debugging stuffs //check stepnum OR pc counter /* if (stepNum == 2396) * { * string x; * }*/ if (myCPU.Decode(curCommand)) { if (Instructions.dontDoItBro == false) { myCPU.Execute(); //check to see if we wrote word to 100000 if (myRam.output) { //prompt user for input //call event handler to update screen if (outputQ.Count == 0) { output = '0'; } else { output = outputQ.Dequeue(); } myRam.output = false; putChar(this, e); } } else { myRegisters.IncrCounter(); } curCommand = myCPU.Fetch(); if (trace) { if (storedBranchPC == 0) { WriteTrace((int)myRegisters.ReadWord(15) - 12); } else { WriteTrace(storedBranchPC); } } } else { if (trace) { WriteTrace((int)myRegisters.ReadWord(15) - 8); } curCommand = 0; } } endRun(this, e); }
public void executeMUL() { myRegister.WriteWord(rd, (myRegister.ReadWord(rs) * myRegister.ReadWord(rm))); }
public void executeLDR() { int operand2int = Convert.ToInt32(operand2); if (u == 0) { operand2int *= -1; } //gettin rn if (p == 1) { addr = (uint)(myRegister.ReadWord(rn) + operand2int); } else if (p == 0) { addr = myRegister.ReadWord(rn); } //performing the load if (bs == 0) { if (!disassembling) { myRegister.WriteWord(rd, myMemory.ReadWord(addr)); } disassembly = "ldr" + Instructions.firstOpcode + " "; } else if (bs == 1) { if (!disassembling) { myRegister.WriteWord(rd, myMemory.ReadByte(addr)); } disassembly = "ldrb" + Instructions.firstOpcode + " "; } disassembly += "r" + Convert.ToString(rd); //writeback? if (p == 1 && w == 1) { if (!disassembling) { myRegister.WriteWord(rn, addr); } disassembly += "!"; } disassembly += ", [r" + Convert.ToString(rn) + opTwoDissasembly + "]"; }
public void executeADD() { myRegister.WriteWord(rd, (myRegister.ReadWord(rn) + operand2)); }