public override void Write(MachineInstructionWriter writer, MachineInstructionWriterOptions options) { if (Offset != 0) { writer.WriteFormat("{0}", Offset); } writer.WriteFormat("("); if (Length != 0) { writer.WriteFormat("{0},", Length); } if (Index != null && Index.Number != 0) { writer.WriteString(Index.Name); if (Base != null && Base.Number != 0) { writer.WriteString(","); writer.WriteString(Base.Name); } } else { writer.WriteString(Base.Name); } writer.WriteFormat(")"); }
private void WriteRegister(RegisterStorage reg, MachineInstructionWriter writer) { int elemSize; string elemName; switch (vectorData) { case VectorData.F32: case VectorData.I32: elemSize = 32; elemName = "s"; break; case VectorData.F16: case VectorData.I16: elemSize = 16; elemName = "h"; break; default: writer.WriteString(reg.Name); return; } writer.WriteFormat("v{0}.", reg.Name.Substring(1)); int nElems = (int)reg.BitSize / elemSize; writer.WriteFormat("{0}{1}", nElems, elemName); }
public override void Write(MachineInstructionWriter writer, MachineInstructionWriterOptions options) { writer.WriteString("("); if (Imm8 < 0) { writer.WriteFormat("-${0:X2},", -Imm8); } else if (Imm8 > 0) { writer.WriteFormat("${0:X2},", Imm8); } writer.WriteString(ARegister.Name); if (XRegister != null) { writer.WriteString(","); writer.WriteString(XRegister.Name); if (XWidth.Size == 2) { writer.WriteString(".w"); } if (Scale > 1) { writer.WriteFormat("*{0}", Scale); } } writer.WriteString(")"); }
public override void Write(MachineInstructionWriter writer, MachineInstructionWriterOptions options) { if (Deferred) { writer.WriteString("@"); } if (Offset != null) { if (Base != null) { writer.WriteString(FormatSignedValue(Offset)); } else { writer.WriteString(FormatUnsignedValue(Offset)); } } if (AutoDecrement) { writer.WriteString("-"); } if (Base != null) { writer.WriteFormat("({0})", Base.Name); } if (AutoIncrement) { writer.WriteString("+"); } if (Index != null) { writer.WriteFormat("[{0}]", Index.Name); } }
public override void Write(MachineInstructionWriter writer, MachineInstructionWriterOptions options) { if (this.PreDecrement) { writer.WriteString("--"); writer.WriteString(Base.Name); return; } if (this.PostIncrement) { writer.WriteString(Base.Name); writer.WriteString("++"); return; } writer.WriteString(Base.Name); writer.WriteString("["); if (Index != null) { writer.WriteString(Index.Name); if (Shift > 0) { writer.WriteFormat("<<{0}", Shift); } } else { writer.WriteFormat("{0}", Offset); } writer.WriteString("]"); }
public override void Write(MachineInstructionWriter writer, MachineInstructionWriterOptions options) { writer.WriteChar('('); writer.WriteString(Base.Name); if (Offset > 0) { writer.WriteFormat("+{0}", Offset); } else if (Offset < 0) { writer.WriteFormat("-{0}", -Offset); } writer.WriteChar(')'); }
public override void Write(MachineInstructionWriter writer, MachineInstructionWriterOptions options) { var v = Value.ToInt32(); var fmt = v < 0 ? "L%-{0:X8}" : "L%{0:X8}"; writer.WriteFormat(fmt, Math.Abs(v)); }
public override void Render(MachineInstructionWriter writer, MachineInstructionWriterOptions options) { writer.WriteFormat("{0} ", Address.ToLinear()); bool inString = false; for (int i = 0; i < Line.Length; ++i) { int b = Line[i]; if (inString) { writer.WriteString(Encoding.UTF8.GetString(Line, i, 1)); inString = (b != 0x22); } else { if (TokenMin <= b && b < TokenMax) { writer.WriteString(TokenStrs[b - TokenMin]); } else { writer.WriteString(Encoding.UTF8.GetString(Line, i, 1)); } inString = (b == 0x22); } } }
private void Write(MachineOperand op, MachineInstructionWriter writer, MachineInstructionWriterOptions options) { var reg = op as RegisterOperand; if (reg != null) { writer.WriteFormat("%{0}", reg.Register.Name); return; } var imm = op as ImmediateOperand; if (imm != null) { writer.WriteString(imm.Value.ToString()); return; } var mem = op as MemoryOperand; if (mem != null) { mem.Write(writer, options); return; } var idx = op as IndexedMemoryOperand; if (idx != null) { idx.Write(writer, options); return; } writer.WriteString(op.ToString()); }
public override void Write(MachineInstructionWriter writer, MachineInstructionWriterOptions options) { if (Deferred) { writer.WriteChar('*'); } if (Base == null) { writer.WriteChar('$'); writer.WriteFormat("0x{0:X}", (uint)Offset); } else { writer.WriteFormat("{0}(%{1})", Offset, Base); } }
/// <summary> /// Write register mask. Bits are: /// 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 /// d0 d1 d2 d3 d4 d5 d6 d7 a0 a1 a2 a3 a4 a5 a6 a7 /// </summary> /// <param name="data"></param> /// <param name="bitPos"></param> /// <param name="incr"></param> /// <param name="regType"></param> /// <param name="writer"></param> public void WriteRegisterSet(uint data, MachineInstructionWriter writer) { string sep = ""; int maxReg = this.Width.Domain == Domain.Real ? 8 : 16; int bitPos = maxReg - 1; for (int i = 0; i < maxReg; i++, --bitPos) { if (bit(data, bitPos)) { int first = i; int run_length = 0; while (i != 7 && i != 15 && bit(data, bitPos - 1)) { --bitPos; ++i; ++run_length; } writer.WriteString(sep); writer.WriteString(GetRegister(first).ToString()); if (run_length > 0) { writer.WriteFormat("-{0}", GetRegister(first + run_length)); } sep = "/"; } } }
public override void Write(MachineInstructionWriter writer, MachineInstructionWriterOptions options) { WriteName(Width.BitSize, VectorRegister, ElementType, Index, writer); if (Index >= 0) { writer.WriteFormat("[{0}]", Index); } }
public override void Write(MachineInstructionWriter writer, MachineInstructionWriterOptions options) { writer.WriteChar('('); if (Base != null) { if (Increment < 0) { writer.WriteFormat("{0}:-", -Increment); } writer.WriteString(Base.Name); if (Index != null) { writer.WriteChar('+'); writer.WriteString(Index.Name); } else if (Offset != null) { int off = Offset.ToInt32(); int absOff; if (off < 0) { writer.WriteChar('-'); absOff = -off; } else { writer.WriteChar('+'); absOff = off; } writer.WriteString("0x"); writer.WriteFormat(OffsetFormat(off), absOff); } if (Increment > 0) { writer.WriteFormat("+:{0}", Increment); } } else { var addr = Address.Ptr16(Offset.ToUInt16()); writer.WriteAddress(addr.ToString(), addr); } writer.WriteChar(')'); }
public override void Write(MachineInstructionWriter writer, MachineInstructionWriterOptions options) { if (Base != null) { if (Indirect) { writer.WriteChar('['); } if (PreIncrement) { writer.WriteFormat("${0:X2},{1}{2}", Math.Abs(Offset.Value), Offset.Value > 0 ? "+" : "-", Base.Name); } else if (PostIncrement) { writer.WriteFormat("${0:X2},{1}{2}", Math.Abs(Offset.Value), Base.Name, Offset.Value > 0 ? "+" : "-"); } else if (Offset != null) { writer.WriteFormat("${0:X4},{1}", Offset.Value, Base.Name); } else { writer.WriteFormat("{0},{1}", Index.Name, Base.Name); } if (Indirect) { writer.WriteChar(']'); } return; } else if (Offset != null) { // Absolute address writer.WriteFormat("${0:X4}", (ushort)Offset.Value); return; } throw new System.NotImplementedException(); }
public override void Write(MachineInstructionWriter writer, MachineInstructionWriterOptions options) { writer.WriteChar('['); writer.WriteString(Base.Name); if (Offset != null && !Offset.IsIntegerZero) { if (PostIndex) { writer.WriteChar(']'); } writer.WriteChar(','); var off = Offset.ToInt32(); if (off < 0) { writer.WriteFormat("#-&{0:X}", -off); } else { writer.WriteFormat("#&{0:X}", off); } } else if (Index != null) { writer.WriteChar(','); writer.WriteString(Index.Name); if (IndexExtend != Mnemonic.Invalid && (IndexExtend != Mnemonic.lsl || IndexShift != 0)) { writer.WriteChar(','); writer.WriteOpcode(IndexExtend.ToString()); if (IndexShift != 0) { writer.WriteString($" #{IndexShift}"); } } } if (!PostIndex) { writer.WriteChar(']'); } if (PreIndex) { writer.WriteChar('!'); } }
public override void Write(MachineInstructionWriter writer, MachineInstructionWriterOptions options) { writer.WriteFormat("[%{0}", Base.Name); if (!Offset.IsNegative) { writer.WriteString("+"); } writer.WriteString(Offset.ToInt16().ToString()); writer.WriteString("]"); }
public override void Write(MachineInstructionWriter writer, MachineInstructionWriterOptions options) { writer.WriteChar('['); var sep = ""; if (Base != null) { writer.WriteString(Base.Name); sep = ","; } if (Offset != 0) { writer.WriteFormat("{0}{1}", sep, Offset); } else if (Index != null) { writer.WriteFormat("{0}{1}", sep, Offset); } writer.WriteChar(']'); }
public override void Write(MachineInstructionWriter writer, MachineInstructionWriterOptions options) { if (Value == 0 && (Mnemonic == Mnemonic.lsl || Mnemonic == Mnemonic.lsr)) { writer.WriteString(Register.Name); } else { writer.WriteFormat("{0}{1}{2}", Register.Name, mpMnemonicToString[Mnemonic], Value); } }
public override void Write(MachineInstructionWriter writer, MachineInstructionWriterOptions options) { if (Base == null) { writer.WriteFormat("&{0:X4}", (ushort)this.Offset); return; } if (Offset > 0) { if (Base == Registers.pc && (options & MachineInstructionWriterOptions.ResolvePcRelativeAddress) != 0) { var addr = writer.Address + 4 + Offset; writer.WriteAddress(addr.ToString(), addr); } else { writer.WriteFormat("{0:X4}({1})", Offset, Base.Name); } } else if (Offset < 0) { if (Base == Registers.pc && (options & MachineInstructionWriterOptions.ResolvePcRelativeAddress) != 0) { var addr = writer.Address + 4 + Offset; writer.WriteAddress(addr.ToString(), addr); } else { writer.WriteFormat("-{0:X4}({1})", -Offset, Base.Name); } } else { writer.WriteChar('@'); writer.WriteString(Base.Name); if (PostIncrement) { writer.WriteChar('+'); } } }
public override void Write(MachineInstructionWriter writer, MachineInstructionWriterOptions options) { int offset = Offset; if (offset < 0) { offset = -offset; writer.WriteChar('-'); } writer.WriteFormat("{0:X}(", offset); writer.WriteString(this.Base.Name); writer.WriteString(")"); }
protected override void RenderOperand(MachineOperand operand, MachineInstructionWriter writer, MachineInstructionWriterOptions options) { switch (operand) { case RegisterOperand rop: writer.WriteFormat("%{0}", rop.Register.Name); break; default: base.RenderOperand(operand, writer, options); break; } }
protected override void RenderOperand(MachineOperand op, MachineInstructionWriter writer, MachineInstructionWriterOptions options) { switch (op) { case RegisterOperand reg: writer.WriteFormat("%{0}", reg.Register.Name); return; default: op.Write(writer, options); return; } }
private void RenderOperand(MachineOperand op, MachineInstructionWriter writer, MachineInstructionWriterOptions options) { switch (op) { case RegisterOperand reg: WriteRegister(reg.Register, writer); break; case ImmediateOperand imm: if (imm.Width.Domain == Domain.Real) { writer.WriteFormat($"#{imm.Value}"); } else { int v = imm.Value.ToInt32(); if (0 <= v && v <= 9) { writer.WriteFormat($"#{imm.Value.ToInt32()}"); } else { writer.WriteFormat($"#&{imm.Value.ToUInt32():X}"); } } break; case AddressOperand addrOp: ulong linAddr = addrOp.Address.ToLinear(); writer.WriteAddress($"#&{linAddr:X}", addrOp.Address); break; default: op.Write(writer, options); break; } }
public override void Write(MachineInstructionWriter writer, MachineInstructionWriterOptions options) { if (PreDecrement) { writer.WriteChar('-'); } writer.WriteString(Base.Name); if (PostIncrement) { writer.WriteChar('+'); } else if (Displacement != 0) { writer.WriteFormat("+{0:X2}", Displacement); } }
public override void Write(MachineInstructionWriter writer, MachineInstructionWriterOptions options) { writer.WriteChar('{'); var sep = ""; foreach (var reg in GetRegisters()) { writer.WriteString(sep); sep = ","; VectorRegisterOperand.WriteName(Width.BitSize, reg, ElementType, Index, writer); } writer.WriteChar('}'); if (Index >= 0) { writer.WriteFormat("[{0}]", Index); } }
public override void Write(MachineInstructionWriter writer, MachineInstructionWriterOptions options) { if (condition > 3) { writer.WriteFormat("cr{0}+", condition >> 2); } var s = ""; switch (condition & 3) { case 0: s = "lt"; break; case 1: s = "gt"; break; case 2: s = "eq"; break; case 3: s = "so"; break; } writer.WriteString(s); }
public override void Write(MachineInstructionWriter writer, MachineInstructionWriterOptions options) { var sep = "{"; int mask = 1; int iStart = -1; for (int i = 0; i < 33; ++i, mask <<= 1) { if ((bitmask & mask) != 0) { if (index >= 0) { writer.WriteString(sep); sep = ","; writer.WriteString(registers[i].Name); writer.WriteFormat("[{0}]", index); } else if (iStart < 0) { // Start a range writer.WriteString(sep); sep = ","; iStart = i; writer.WriteString(registers[i].Name); } } else { if (index < 0) { if (0 <= iStart && iStart < i - 1) { writer.WriteChar('-'); writer.WriteString(registers[i - 1].Name); } iStart = -1; } } } writer.WriteChar('}'); }
protected override void RenderOperand(MachineOperand op, MachineInstructionWriter writer, MachineInstructionWriterOptions options) { switch (op) { case RegisterOperand reg: writer.WriteFormat("%{0}", reg.Register.Name); return; case ImmediateOperand imm: writer.WriteString(imm.Value.ToString()); return; case MemoryOperand mem: mem.Write(writer, options); return; case IndexedMemoryOperand idx: idx.Write(writer, options); return; } writer.WriteString(op.ToString()); }
public override void Write(MachineInstructionWriter writer, MachineInstructionWriterOptions options) { writer.WriteChar('@'); if (this.Deferred) { writer.WriteChar('@'); } if (Base != null) { if (this.PreDecrement) { writer.WriteChar('-'); writer.WriteString(Base.Name); } else if (this.PostIncrement) { writer.WriteString(Base.Name); writer.WriteChar('+'); } else if (Offset != 0) { writer.WriteChar('('); writer.WriteFormat("{0}:{1},", Offset, AddressWidth !.BitSize); writer.WriteString(Base.Name); writer.WriteChar(')'); } else { writer.WriteString(Base.Name); } } else { //$REFACTOR: does it make sense to move absolute addresses to their own class? writer.WriteAddress($"0x{(uint) Offset:X}:{AddressWidth!.BitSize}", Address.Ptr32((uint)Offset)); } }
protected override void RenderOperand(MachineOperand op, MachineInstructionWriter writer, MachineInstructionWriterOptions options) { switch (op) { case RegisterOperand reg: writer.WriteString(reg.Register.Name); return; case ImmediateOperand imm: var sbImm = new StringBuilder("#"); var sImm = imm.Value.ToString(); writer.WriteString(sImm); return; case MemoryOperand mem: if (Prefix != null) { writer.WriteFormat("{0}:", Prefix.Name); } writer.WriteChar('['); if (mem.Base != null) { writer.WriteString(mem.Base.Name); if (mem.Index != null) { writer.WriteFormat("+{0}", mem.Index.Name); } else if (mem.Offset != 0) { if (mem.Offset >= 0xA0) { writer.WriteFormat("+0{0:X2}h", mem.Offset); } else { writer.WriteFormat("+{0:X2}h", mem.Offset); } } } else { if (mem.Offset >= 0xA000) { writer.WriteFormat("0{0:X4}h", mem.Offset); } else { writer.WriteFormat("{0:X4}h", mem.Offset); } if (mem.Index != null) { writer.WriteFormat("+{0}", mem.Index.Name); } } writer.WriteChar(']'); return; case BitOperand bit: this.RenderOperand(bit.Operand, writer, options); writer.WriteFormat(".{0}", bit.BitPosition); return; case AddressOperand aop: writer.WriteAddress(aop.Address.ToString(), aop.Address); return; case RegisterBankOperand rbop: writer.WriteFormat("rb{0}", rbop.Bank); return; case FlagGroupOperand grf: writer.WriteString(grf.FlagGroup.Name); return; } throw new NotImplementedException($"Rl78Instruction - RenderOperand {op.GetType().Name}."); }