public void Destination16Test() { var translation = new OpcodeTranslation(); Assert.AreEqual(16, translation.Destination16); translation.Destination16 = 23; Assert.AreEqual(23, translation.Destination16); }
public void Destination32Test() { var translation = new OpcodeTranslation(); Assert.AreEqual(0, translation.Destination32); translation.Destination32 = 23; Assert.AreEqual(23, translation.Destination32); }
public void Destination16WordTest() { var translation = new OpcodeTranslation(); Assert.AreEqual(0, translation.Destination16Word); translation.Destination16Word = 24; Assert.AreEqual(24, translation.Destination16Word); }
public void Imm6Test() { var translation = new OpcodeTranslation(); Assert.AreEqual(0, translation.Imm6); translation.Imm6 = 42; Assert.AreEqual(42, translation.Imm6); }
public void DisplacementTest() { var translation = new OpcodeTranslation(); Assert.AreEqual(0, translation.Displacement); translation.Displacement = 63; Assert.AreEqual(63, translation.Displacement); }
public void Imm8Test() { var translation = new OpcodeTranslation(); Assert.AreEqual(0, translation.Imm8); translation.Imm8 = 123; Assert.AreEqual(123, translation.Imm8); }
public void BitNumberTest() { var translation = new OpcodeTranslation(); Assert.AreEqual(0, translation.BitNumber); translation.BitNumber = 2; Assert.AreEqual(2, translation.BitNumber); }
public void DesRoundTest() { var translation = new OpcodeTranslation(); Assert.AreEqual(0, translation.DesRound); translation.DesRound = 15; Assert.AreEqual(15, translation.DesRound); }
public override void Compile(AsmParser parser, AsmSection output) { var zToken = parser.ReadToken(TokenType.Literal); if (zToken.StringValue.ToLower() != "z") throw new TokenException("Z register expected", zToken); parser.ReadToken(TokenType.Comma); var dest = parser.ReadReg32(); var translation = new OpcodeTranslation { Opcode = _opcodeTemplate, Destination32 = dest }; output.EmitCode(translation.Opcode); }
protected override void Compile(AsmSection output) { var translation = new OpcodeTranslation { Opcode = _opcodeTemplate, Port64 = Port, Destination32 = Register }; output.EmitCode(translation.Opcode); }
protected override void Compile(AsmSection output) { var translation = new OpcodeTranslation { Opcode = _opcodeTemplate, Destination16 = Register, Imm8 = Value }; output.EmitCode(translation.Opcode); }
protected override void Compile(AsmSection output) { foreach (var reg in Registers) { var translation = new OpcodeTranslation { Opcode = _opcodeTemplate, Destination32 = reg }; output.EmitCode(translation.Opcode); } }
public override void Compile(AsmParser parser, AsmSection output) { var dest = parser.ReadReg16(); parser.ReadToken(TokenType.Comma); var value = parser.ReadByte(); var translation = new OpcodeTranslation { Opcode = _opcodeTemplate, Destination16 = dest, Imm8 = (byte)(255 - value) }; output.EmitCode(translation.Opcode); }
protected override void Compile(AsmSection output) { var translation = new OpcodeTranslation { Opcode = _opcodeTemplate, Port32 = Port, BitNumber = Bit }; output.EmitCode(translation.Opcode); }
protected override void Compile(AsmSection output) { var translation = new OpcodeTranslation { Opcode = _opcodeTemplate, Destination32 = Destination }; output.EmitCode(translation.Opcode); output.EmitCode(Address); }
public void Offset7Test() { var translation = new OpcodeTranslation(); Assert.AreEqual(0, translation.Offset7); translation.Offset7 = 62; Assert.AreEqual(62, translation.Offset7); translation.Offset7 = -62; Assert.AreEqual(-62, translation.Offset7); }
public static BaseOpcode Parse(Stream stream) { var bytecode = ReadUShort(stream); var translation = new OpcodeTranslation { Opcode = bytecode }; switch (bytecode) { case 0x0000: return new NopOpcode(); case 0x9508: return new RetOpcode(); case 0x9509: return new IcallOpcode(); case 0x9518: return new RetiOpcode(); case 0x95a8: return new WdrOpcode(); case 0x95c8: return new LpmOpcode(); } if ((bytecode & 0xff0f) == 0x9408) { return BaseStatusBitOpcode.FromOpcode(bytecode); } if ((bytecode & 0xff00) == 0x9700) { return new SbiwOpcode { Register = translation.RegW24, Value = translation.Imm6 }; } if ((bytecode & 0xff00) == 0x9600) { return new AdiwOpcode { Register = translation.RegW24, Value = translation.Imm6 }; } if ((bytecode & 0xff00) == 0x0100) { return new MovwOpcode { Register = translation.Register16Word, Destination = translation.Destination16Word }; } if ((bytecode & 0xff00) == 0x9800) { return new CbiOpcode { Port = translation.Port32, Bit = translation.BitNumber }; } if ((bytecode & 0xff00) == 0x9a00) { return new SbiOpcode { Port = translation.Port32, Bit = translation.BitNumber }; } if ((bytecode & 0xff00) == 0x9b00) { return new SbisOpcode { Port = translation.Port32, Bit = translation.BitNumber }; } if ((bytecode & 0xff00) == 0x9900) { return new SbicOpcode { Port = translation.Port32, Bit = translation.BitNumber }; } //x if ((bytecode & 0xfe0f) == 0x900c) { return new LdOpcode { Destination = translation.Destination32, Operand = translation.IndirectOperand }; } if ((bytecode & 0xfe0f) == 0x900d) { return new LdOpcode { Destination = translation.Destination32, Operand = translation.IndirectOperand }; } if ((bytecode & 0xfe0f) == 0x900e) { return new LdOpcode { Destination = translation.Destination32, Operand = translation.IndirectOperand }; } //y if ((bytecode & 0xfe0f) == 0x8008) { return new LdOpcode { Destination = translation.Destination32, Operand = translation.IndirectOperand }; } if ((bytecode & 0xfe0f) == 0x9009) { return new LdOpcode { Destination = translation.Destination32, Operand = translation.IndirectOperand }; } if ((bytecode & 0xfe0f) == 0x900a) { return new LdOpcode { Destination = translation.Destination32, Operand = translation.IndirectOperand }; } if ((bytecode & 0xd208) == 0x8008) { return new LdOpcode { Destination = translation.Destination32, Operand = translation.IndirectOperand }; } //z if ((bytecode & 0xfe0f) == 0x8000) { return new LdOpcode { Destination = translation.Destination32, Operand = translation.IndirectOperand }; } if ((bytecode & 0xfe0f) == 0x9001) { return new LdOpcode { Destination = translation.Destination32, Operand = translation.IndirectOperand }; } if ((bytecode & 0xfe0f) == 0x9002) { return new LdOpcode { Destination = translation.Destination32, Operand = translation.IndirectOperand }; } if ((bytecode & 0xd208) == 0x8000) { return new LdOpcode { Destination = translation.Destination32, Operand = translation.IndirectOperand }; } if ((bytecode & 0xfe0f) == 0x9000) { return new LdsOpcode { Destination = translation.Destination32, Address = ReadUShort(stream) }; } //x if ((bytecode & 0xfe0f) == 0x920c) { return new StOpcode { Source = translation.Destination32, Operand = translation.IndirectOperand }; } if ((bytecode & 0xfe0f) == 0x920d) { return new StOpcode { Source = translation.Destination32, Operand = translation.IndirectOperand }; } if ((bytecode & 0xfe0f) == 0x920e) { return new StOpcode { Source = translation.Destination32, Operand = translation.IndirectOperand }; } //y if ((bytecode & 0xfe0f) == 0x8208) { return new StOpcode { Source = translation.Destination32, Operand = translation.IndirectOperand }; } if ((bytecode & 0xfe0f) == 0x9209) { return new StOpcode { Source = translation.Destination32, Operand = translation.IndirectOperand }; } if ((bytecode & 0xfe0f) == 0x920a) { return new StOpcode { Source = translation.Destination32, Operand = translation.IndirectOperand }; } if ((bytecode & 0xd208) == 0x8208) { return new StOpcode { Source = translation.Destination32, Operand = translation.IndirectOperand }; } //z if ((bytecode & 0xfe0f) == 0x8200) { return new StOpcode { Source = translation.Destination32, Operand = translation.IndirectOperand }; } if ((bytecode & 0xfe0f) == 0x9201) { return new StOpcode { Source = translation.Destination32, Operand = translation.IndirectOperand }; } if ((bytecode & 0xfe0f) == 0x9202) { return new StOpcode { Source = translation.Destination32, Operand = translation.IndirectOperand }; } if ((bytecode & 0xd208) == 0x8200) { return new StOpcode { Source = translation.Destination32, Operand = translation.IndirectOperand }; } if ((bytecode & 0xfe0f) == 0x9200) { return new StsOpcode { Source = translation.Destination32, Address = ReadUShort(stream) }; } if ((bytecode & 0xfe08) == 0xf800) { return new BldOpcode { Register = translation.Destination32, Bit = translation.BitNumber }; } if ((bytecode & 0xfe08) == 0xfa00) { return new BstOpcode { Register = translation.Destination32, Bit = translation.BitNumber }; } if ((bytecode & 0xfe08) == 0xfc00) { return new SbrcOpcode { Register = translation.Destination32, Bit = translation.BitNumber }; } if ((bytecode & 0xfe08) == 0xfe00) { return new SbrsOpcode { Register = translation.Destination32, Bit = translation.BitNumber }; } if ((bytecode & 0xfe0e) == 0x9004) { return new LpmOpcode { Destination = translation.Destination32, Increment = translation.Increment }; } if ((bytecode & 0xffef) == 0x95e8) { return new SpmOpcode { PostIncrement = translation.SpmIncrement }; } if ((bytecode & 0xfe0f) == 0x920f) { return new PushOpcode { Register = translation.Destination32 }; } if ((bytecode & 0xfe0f) == 0x900f) { return new PopOpcode { Register = translation.Destination32 }; } if ((bytecode & 0xfe0f) == 0x9402) { return new SwapOpcode { Register = translation.Destination32 }; } if ((bytecode & 0xfe00) == 0x9400) { var subop = bytecode & 0xf; switch (subop) { case 0x00: return new ComOpcode { Register = translation.Destination32 }; case 0x01: return new NegOpcode { Register = translation.Destination32 }; case 0x03: return new IncOpcode { Register = translation.Destination32 }; case 0x05: return new AsrOpcode { Register = translation.Destination32 }; case 0x06: return new LsrOpcode { Register = translation.Destination32 }; case 0x07: return new RorOpcode { Register = translation.Destination32 }; case 0x0a: return new DecOpcode { Register = translation.Destination32 }; } } if ((bytecode & 0xfc00) == 0x0400) { return new CpcOpcode { Register = translation.Register32, Destination = translation.Destination32 }; } if ((bytecode & 0xfc00) == 0x0800) { return new SbcOpcode { Register = translation.Register32, Destination = translation.Destination32 }; } if ((bytecode & 0xfc00) == 0x0c00) { return new AddOpcode { Register = translation.Register32, Destination = translation.Destination32 }; } if ((bytecode & 0xfc00) == 0x1000) { return new CpseOpcode { Register = translation.Register32, Destination = translation.Destination32 }; } if ((bytecode & 0xfc00) == 0x1400) { return new CpOpcode { Register = translation.Register32, Destination = translation.Destination32 }; } if ((bytecode & 0xfc00) == 0x1800) { return new SubOpcode { Register = translation.Register32, Destination = translation.Destination32 }; } if ((bytecode & 0xfc00) == 0x1c00) { return new AdcOpcode { Register = translation.Register32, Destination = translation.Destination32 }; } if ((bytecode & 0xfc00) == 0x2000) { return new AndOpcode { Register = translation.Register32, Destination = translation.Destination32 }; } if ((bytecode & 0xfc00) == 0x2400) { return new EorOpcode { Register = translation.Register32, Destination = translation.Destination32 }; } if ((bytecode & 0xfc00) == 0x2800) { return new OrOpcode { Register = translation.Register32, Destination = translation.Destination32 }; } if ((bytecode & 0xfc00) == 0x2c00) { return new MovOpcode { Register = translation.Register32, Destination = translation.Destination32 }; } if ((bytecode & 0xfc00) == 0x9c00) { return new MulOpcode { Register = translation.Register32, Destination = translation.Destination32 }; } if ((bytecode & 0xf800) == 0xb800) { return new OutOpcode { Port = translation.Port64, Register = translation.Destination32 }; } if ((bytecode & 0xf800) == 0xb000) { return new InOpcode { Port = translation.Port64, Register = translation.Destination32 }; } if ((bytecode & 0xf800) == 0xf000) { return BaseStatusBitOffset7Opcode.FromOpcode(bytecode); } if ((bytecode & 0xf000) == 0xc000) { return new RjmpOpcode { Delta = (short)(translation.Offset12 * 2) }; } if ((bytecode & 0xf000) == 0xd000) { return new RcallOpcode { Delta = (short)(translation.Offset12 * 2) }; } if ((bytecode & 0xfe0e) == 0x940e) { var high = translation.Offset22High; var low = ReadUShort(stream); return new CallOpcode { Target = ((high << 16) + low) << 1 }; } if ((bytecode & 0xfe0e) == 0x940c) { var high = translation.Offset22High; var low = ReadUShort(stream); return new JmpOpcode { Target = ((high << 16) + low) << 1 }; } if ((bytecode & 0xf000) == 0x3000) { return new CpiOpcode { Register = translation.Destination16, Value = translation.Imm8 }; } if ((bytecode & 0xf000) == 0x4000) { return new SbciOpcode { Register = translation.Destination16, Value = translation.Imm8 }; } if ((bytecode & 0xf000) == 0x5000) { return new SubiOpcode { Register = translation.Destination16, Value = translation.Imm8 }; } if ((bytecode & 0xf000) == 0x6000) { return new OriOpcode { Register = translation.Destination16, Value = translation.Imm8 }; } if ((bytecode & 0xf000) == 0x7000) { return new AndiOpcode { Register = translation.Destination16, Value = translation.Imm8 }; } if ((bytecode & 0xf000) == 0xe000) { return new LdiOpcode { Register = translation.Destination16, Value = translation.Imm8 }; } //if ((bytecode & 0xd200) == 0x8000) { // return new LddOpCode { Register = translation.Destination32, BaseRegister = translation.YZSelector, Delta = translation.YZOffset }; //} //if ((bytecode & 0xd200) == 0x8200) { // return new StdOpCode { Register = translation.Destination32, BaseRegister = translation.YZSelector, Delta = translation.YZOffset }; //} return new UnknownOpcode { Opcode = bytecode }; }
public void Offset12Test() { var translation = new OpcodeTranslation(); Assert.AreEqual(0, translation.Offset12); translation.Offset12 = 620; Assert.AreEqual(620, translation.Offset12); translation.Offset12 = -620; Assert.AreEqual(-620, translation.Offset12); }
public void Offset22HighTest() { var translation = new OpcodeTranslation(); Assert.AreEqual(0, translation.Offset22High); translation.Offset22High = 62; Assert.AreEqual(62, translation.Offset22High); }
public void Port64Test() { var translation = new OpcodeTranslation(); Assert.AreEqual(0, translation.Port64); translation.Port64 = 54; Assert.AreEqual(54, translation.Port64); }
public void Port32Test() { var translation = new OpcodeTranslation(); Assert.AreEqual(0, translation.Port32); translation.Port32 = 12; Assert.AreEqual(12, translation.Port32); }
public void Register16Test() { var translation = new OpcodeTranslation(); Assert.AreEqual(16, translation.Register16); translation.Register16 = 23; Assert.AreEqual(23, translation.Register16); }
public void Register16WordTest() { var translation = new OpcodeTranslation(); Assert.AreEqual(0, translation.Register16Word); translation.Register16Word = 24; Assert.AreEqual(24, translation.Register16Word); }
public void Register32Test() { var translation = new OpcodeTranslation(); Assert.AreEqual(0, translation.Register32); translation.Register32 = 23; Assert.AreEqual(23, translation.Register32); }
public void RegisterW24Test() { var translation = new OpcodeTranslation(); Assert.AreEqual(24, translation.RegW24); translation.RegW24 = 28; Assert.AreEqual(28, translation.RegW24); }
public void StatusBitNumberTest() { var translation = new OpcodeTranslation(); Assert.AreEqual(0, translation.StatusBitNumber); translation.StatusBitNumber = 3; Assert.AreEqual(3, translation.StatusBitNumber); }