//stores word to memory address: public override void Execute(uint Rn, uint Rd, Offset offst) { int EA = GetEffAddr(Rn, offst); //((int)Rn + (U == 1 ? offst.GetValue() : -offst.GetValue())) & 0xFFFFFFFF; if (EA == 0x100000) { I_Console_Ref.Append((char)CPU.GetRegr(I_Reg, (int)Rd)); } else { if (B == 1) { byte b = Convert.ToByte(CPU.GetRegr(I_Reg, (int)Rd) & 0xFF); I_RAM.WriteByte(b, EA); } else { I_RAM.WriteWord(CPU.GetRegr(I_Reg, (int)Rd), EA); } if (W == 1) { CPU.SetReg(I_Reg, (int)Rn, EA); } } }
public override int GetValue() { reg = Memory.ExtractBits(OffBits, 28, 31); shift = Memory.ExtractBits(OffBits, 25, 26); imm = Memory.ExtractBits(OffBits, 20, 24); return((int)BarrelShift.Compute(shift, (uint)CPU.GetRegr(Offset_Regs, (int)reg), imm)); }
public override int GetValue() { reg = (int)Memory.ExtractBits(OperBits, 28, 31); shift = Memory.ExtractBits(OperBits, 25, 26); reg2 = (int)Memory.ExtractBits(OperBits, 20, 23); return((int)BarrelShift.Compute(shift, (uint)CPU.GetRegr(Oper2Regs, reg), (uint)CPU.GetRegr(Oper2Regs, reg2))); }
//Rd := Rm * Rs; public override void Execute(uint Rd, uint Rm, uint Rs) { int first = CPU.GetRegr(I_Reg, (int)Rm); int second = CPU.GetRegr(I_Reg, (int)Rs); long res = (first * second) & 0xFFFFFFFF; CPU.SetReg(I_Reg, (int)Rd, (int)res); }
public override void Execute(int offset) { int pc = CPU.GetRegr(I_Reg, 15); //returns pc + 8; pc -= 4; //this might be a problem if (L == 1) { CPU.SetReg(I_Reg, 14, pc); } CPU.SetReg(I_Reg, 15, ((int)InstAddr + 8 + offset)); }
public override void Execute(uint Rn, List <int> Reglist) { int EA = CPU.GetRegr(I_Reg, (int)Rn); foreach (int i in Reglist) { int val = I_RAM.ReadWord(EA); CPU.SetReg(I_Reg, i, val); EA += 4; } if (W == 1) { CPU.SetReg(I_Reg, (int)Rn, EA); } }
//pushes register list onto stack public override void Execute(uint Rn, List <int> Reglist) { int EA = CPU.GetRegr(I_Reg, (int)Rn); EA -= (4 * Reglist.Count); if (W == 1) { CPU.SetReg(I_Reg, (int)Rn, EA); } foreach (int i in Reglist) { int val = CPU.GetRegr(I_Reg, i); I_RAM.WriteWord(val, EA); EA += 4; } }
//Update flags after Rn - shifter_operand public override void Execute(uint Rn, uint Rd, Operand2 oper2) { uint rnval = (uint)CPU.GetRegr(I_Reg, (int)Rn), op2val = (uint)oper2.GetValue(); int val = (int)(rnval - op2val); uint N = Memory.ExtractBits((uint)val, 0, 0); int Z = val == 0 ? 1 : 0; int C = op2val <= rnval ? 1 : 0; //May not be correctly handling C flag will need to modify int rnv = (int)rnval, op2v = (int)op2val; val = rnv - op2v; int V = (rnv > 0 && op2v < 0 && val < 0) || (rnv < 0 && op2v > 0 && val > 0) ? 1 : 0; bool[] flags = { Convert.ToBoolean(N), Convert.ToBoolean(Z), Convert.ToBoolean(C), Convert.ToBoolean(V) }; for (int i = 0; i < 4; ++i) { I_Reg.SetFlag(4 * 16, i, flags[i]); } }
//Rd := shifter_operand (no Rn) public override void Execute(uint Rn, uint Rd, Operand2 oper2) { CPU.SetReg(I_Reg, (int)Rd, oper2.GetValue()); int mode = (int)Memory.ExtractBits((uint)CPU.GetRegr(I_Reg, 16), 27, 31); if (sbit && Rd == 15) { int spsr = CPU.GetRegr(I_Reg, 16); if (mode == 0b10010) { spsr = CPU.GetRegr(I_Reg, 19); //because I had to place them weirdly. //CPU.SetReg(I_Reg, (int)Rd, oper2.GetValue() - 4); //adjust the LR for the PC when IRQ } else if (mode == 0b10011) { spsr = CPU.GetRegr(I_Reg, 22); } CPU.SetReg(I_Reg, 16, spsr); } }
public override void Execute(int Rm) { uint rm0 = (uint)CPU.GetRegr(I_Reg, Rm) & 0xFFFFFFFE; CPU.SetReg(I_Reg, 15, (int)(rm0)); }
public int GetEffAddr(uint rn, Offset offst) { long EA = (CPU.GetRegr(I_Reg, (int)rn) + (U == 1 ? offst.GetValue() : -offst.GetValue())) & 0xFFFFFFFF; return((int)EA); }
//Rd := Rn AND NOT(shifter_operand) public override void Execute(uint Rn, uint Rd, Operand2 oper2) { int val = CPU.GetRegr(I_Reg, (int)Rn) & (~oper2.GetValue()); CPU.SetReg(I_Reg, (int)Rd, val); }