public static RegisterFile Lpm(RegisterFile registerFile, byte d, AvrSim.Flash programMemory, object[] arguments) { var postIncrement = (bool)arguments[0]; var word = (uint)(registerFile.GetWide(Core.R_Z) >> 1); var MSB = (registerFile.GetWide(Core.R_Z) & 1) != 0; var data = programMemory.GetInstruction(word); byte value; if (MSB) { value = (byte)(data >> 8); } else { value = (byte)(data & 0xff); } registerFile = registerFile.WithRegister(d, value); if (postIncrement) { registerFile = registerFile.WithWide(Core.R_Z, z => (ushort)(z + 1)); } return(registerFile); }
public static RegisterFile Std(RegisterFile registerFile, byte r, byte q, MemoryBus memoryBus, object[] arguments) { var register = (byte)arguments[0]; memoryBus.Store((ushort)(registerFile.GetWide(register) + q), registerFile[r]); return(registerFile); }
public static RegisterFile Lpm(RegisterFile registerFile, AvrSim.Flash programMemory) { var word = (uint)(registerFile.GetWide(Core.R_Z) >> 1); var MSB = (registerFile.GetWide(Core.R_Z) & 1) != 0; var data = programMemory.GetInstruction(word); byte value; if (MSB) { value = (byte)(data >> 8); } else { value = (byte)(data & 0xff); } return(registerFile.WithRegister(0, value)); }
public static RegisterFile Adiw(RegisterFile registerFile, byte K, byte d) { d = (byte)(24 + 2 * d); var Rdh = registerFile[d + 1]; var Rdl = registerFile[d]; ushort R = (ushort)(registerFile.GetWide(d) + K); var statusRegister = registerFile.StatusRegister .WithTwosComplementOverflow(Rdh.BitIsCleared(7) & R.BitIsSet(15)) .WithNegative(R.BitIsSet(15)) .WithZero(R == 0) .WithCarry(R.BitIsCleared(15) & Rdh.BitIsSet(7)); statusRegister = statusRegister.WithSigned(statusRegister.N & statusRegister.V); return(registerFile.WithWide(d, R) .WithStatusRegister(statusRegister)); }
public static RegisterFile St(RegisterFile registerFile, byte r, MemoryBus memoryBus, object[] arguments) { var register = (byte)arguments[0]; var change = (int)arguments[1]; var preDecrement = change == -1; var postIncrement = change == 1; if (preDecrement) { registerFile = registerFile.WithWide(register, v => (ushort)(v - 1)); } memoryBus.Store(registerFile.GetWide(register), r); if (postIncrement) { registerFile = registerFile.WithWide(register, v => (ushort)(v + 1)); } return(registerFile); }
public static RegisterFile Ldd(RegisterFile registerFile, byte d, byte q, MemoryBus memoryBus, object[] arguments) { var register = (byte)arguments[0]; return(registerFile.WithRegister(d, memoryBus.Load((ushort)(registerFile.GetWide(register) + q)))); }