//-------------------------------------------------------------- // Purpose: Calculates the address to reference for Load/Store instructions // Returns: The uint value of the address to reference //-------------------------------------------------------------- private static uint GetLdStoreAddress(LdStore instr) { uint refAddress, offset; if (Memory.ExtractBits(instr.instructionData, 25, 25) == 0) { offset = (uint)instr.immediateVal; // immediate offset } else { offset = BarrelShifter.rotateVal(Computer.GetCPU().registers.ReadWord((uint)(instr.RM * 4)), instr.shiftType, instr.shiftVal); // imm shifted register } if (instr.RN * 4 == (int)regs.PC) { offset += 4; // to take into account PC reference } if (!instr.U) { refAddress = Computer.GetCPU().registers.ReadWord((uint)(instr.RN * 4)) - offset; } else { uint val = Computer.GetCPU().registers.ReadWord((uint)(instr.RN * 4)); refAddress = val + offset; } return(refAddress); }
//-------------------------------------------------------------- // Purpose: Computes the value of operand2 in data processing instructions // Returns: The uint value of the instruction's operand2 //-------------------------------------------------------------- private static uint ComputeValue(Data instr) { op2Type op2 = Operation.CheckOperand2(instr); shiftType shift = Operation.CheckShiftType(instr); Memory registers = Computer.GetCPU().registers; uint value = 0, adjustPC = 0; if (instr.RM * 4 == (int)regs.PC || instr.RS * 4 == (int)regs.PC) { adjustPC = 4; } switch (op2) { case op2Type.imm: value = BarrelShifter.rotateVal((uint)instr.immediateVal, (byte)shiftType.ror, (uint)instr.rotateVal * 2); break; case op2Type.reg_imm: value = BarrelShifter.rotateVal(registers.ReadWord((uint)instr.RM * 4) + adjustPC, instr.shiftType, instr.shiftVal); break; case op2Type.reg_reg: value = BarrelShifter.rotateVal(registers.ReadWord((uint)instr.RM * 4) + adjustPC, instr.shiftType, registers.ReadWord((uint)instr.RS * 4) + adjustPC); break; } return(value); }
private static uint ComputeBranchAddress(Branch instr) { uint val = (uint)instr.immediateVal; uint val2 = val << 8; uint addr = BarrelShifter.rotateVal((uint)instr.immediateVal << 8, 0x02, 6); //addr <<= 2; uint PC = Computer.GetCPU().registers.ReadWord((uint)regs.PC) + 8; addr += Computer.GetCPU().registers.ReadWord((uint)regs.PC) + 8; return(addr); }