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 (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(")"); }
public override void Write(MachineInstructionWriter writer, MachineInstructionWriterOptions options) { if (Base != null) { if (Offset != null) { int offset = Offset.ToInt32(); string fmt; if (offset > 0) { fmt = "({0}+{1:X2})"; } else if (offset < 0) { offset = -offset; fmt = "({0}-{1:X2})"; } else { fmt = "({0})"; } writer.WriteString(string.Format(fmt, Base, offset)); } else { writer.WriteString(string.Format("({0})", Base)); } } else { writer.WriteString("("); writer.WriteAddress(string.Format("{0:X4}", Offset.ToUInt16()), Address.Ptr16(Offset.ToUInt16())); writer.WriteString(")"); } }
private void WriteOp(MachineOperand op, MachineInstructionWriter writer) { var rop = op as RegisterOperand; if (rop != null) { writer.WriteString(rop.Register.Name); return; } var immop = op as ImmediateOperand; if (immop != null) { writer.WriteString(immop.Value.ToString()); return; } var addrop = op as AddressOperand; if (addrop != null) { //$TODO: 32-bit? writer.WriteAddress(string.Format("{0:X16}", addrop.Address.ToLinear()), addrop.Address); return; } throw new NotImplementedException(); }
public override void Write(MachineInstructionWriter writer, MachineInstructionWriterOptions options) { writer.WriteString(Index.Name); writer.WriteString("("); writer.WriteString(Base.Name); writer.WriteString(")"); }
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 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); } } }
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 (iStart < 0) { // Start a range writer.WriteString(sep); sep = ","; iStart = i; writer.WriteString(registers[i].Name); } } else { if (0 <= iStart && iStart < i - 1) { writer.WriteChar('-'); writer.WriteString(registers[i - 1].Name); } iStart = -1; } } writer.WriteChar('}'); }
/// <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) { writer.WriteChar('{'); writer.WriteString(BitOffset.ToString()); writer.WriteChar(':'); writer.WriteString(BitWidth.ToString()); writer.WriteChar('}'); }
public override void Write(MachineInstructionWriter writer, MachineInstructionWriterOptions options) { writer.WriteString("("); writer.WriteString(MaxRegister.Name); writer.WriteString(":"); writer.WriteString(MinRegister.Name); writer.WriteString(")"); }
public override void Write(MachineInstructionWriter writer, MachineInstructionWriterOptions options) { if (Negated) { writer.WriteString("/"); } writer.WriteString(Register.Name); writer.WriteString($".{Bit}"); }
public override void Write(MachineInstructionWriter writer, MachineInstructionWriterOptions options) { if (!ImmediateValue.IsValid) { writer.WriteString("???"); return; } writer.WriteString(FormatValue(ImmediateValue, false, "{0}0x{1}")); }
public override void Write(MachineInstructionWriter writer, MachineInstructionWriterOptions options) { if (FSRNum == 255) { writer.WriteString("FSR"); return; } writer.WriteString($"FSR{FSRNum}"); }
public override void Write(MachineInstructionWriter writer, MachineInstructionWriterOptions options) { if (Offset != null) { writer.WriteString(MachineOperand.FormatValue(Offset, false, M68kDisassembler.HexStringFormat)); } writer.WriteString("("); writer.WriteString(Base.Name); writer.WriteString(")"); }
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) { if (Index != null) { writer.WriteString("@"); writer.WriteString(Register.Name); writer.WriteString("+"); writer.WriteString(Index.Name); } else { if (DirectAddress != null) { writer.WriteString("["); if (DirectAddress is Constant c) { writer.WriteString(c.ToUInt16().ToString("X4")); } else { writer.WriteString(DirectAddress.ToString()); } writer.WriteString("]"); } else { writer.WriteString($"@{Register.Name}"); } } }
public override void Write(MachineInstructionWriter writer, MachineInstructionWriterOptions options) { string sep = ""; foreach (var reg in GetRegisters()) { writer.WriteString(sep); sep = ","; writer.WriteString(reg.Name); } }
private void Write(MachineOperand op, MachineInstructionWriter writer, MachineInstructionWriterOptions options) { if (op is AddressOperand && (base.InstructionClass & InstrClass.Transfer) == 0) { writer.WriteString("&"); } if (op is ImmediateOperand && opcode != Opcode.call) { writer.WriteString("#"); } op.Write(writer, options); }
protected override void RenderOperand(MachineOperand op, MachineInstructionWriter writer, MachineInstructionWriterOptions options) { if (op is AddressOperand && (base.InstructionClass & InstrClass.Transfer) == 0) { writer.WriteString("&"); } if (op is ImmediateOperand && Mnemonic != Mnemonics.call) { writer.WriteString("#"); } op.Write(writer, options); }
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(")"); }
public override void Write(MachineInstructionWriter writer, MachineInstructionWriterOptions options) { string fmt; switch (Mode) { case AddressMode.RegDef: fmt = "@{0}"; break; case AddressMode.AutoIncr: fmt = "({0})+"; break; case AddressMode.AutoIncrDef: fmt = "@({0})+"; break; case AddressMode.AutoDecr: fmt = "-({0})"; break; case AddressMode.AutoDecrDef: fmt = "@-({0})"; break; case AddressMode.Indexed: if (Register == Registers.pc && (options & MachineInstructionWriterOptions.ResolvePcRelativeAddress) != 0) { var ea = writer.Address + 4 + EffectiveAddress; writer.WriteAddress("@#" + ea.ToString(), ea); return; } fmt = "{1:X4}({0})"; break; case AddressMode.IndexedDef: if (Register == Registers.pc && (options & MachineInstructionWriterOptions.ResolvePcRelativeAddress) != 0) { writer.WriteString("@("); var ea = writer.Address + 4 + EffectiveAddress; writer.WriteAddress(ea.ToString(), ea); writer.WriteString(")"); return; } fmt = "@{1:X4}({0})"; break; //case AddressMode.Immediate : fmt = "#{1:X4}"; break; case AddressMode.Absolute: writer.WriteAddress( string.Format("@#{0:X4}", EffectiveAddress), Address.Ptr16(EffectiveAddress)); return; default: throw new NotImplementedException(string.Format("Unknown mode {0}.", Mode)); } writer.WriteString(string.Format(fmt, Register, EffectiveAddress)); }
public override void Render(MachineInstructionWriter writer, MachineInstructionWriterOptions options) { writer.WriteOpcode(Opcode.ToString()); writer.Tab(); switch (op1) { case PICOperandDataMemoryAddress srcmem: if (PICRegisters.TryGetRegister(srcmem.DataTarget, out var srcreg)) { writer.WriteString($"{srcreg.Name}"); } else { srcmem.Write(writer, options); } break; case PICOperandFSRIndexation srcidx: if (srcidx.Mode != FSRIndexedMode.FSR2INDEXED) { throw new InvalidOperationException($"Invalid FSR2 indexing mode: {srcidx.Mode}."); } writer.WriteString($"[{srcidx.Offset:X2}]"); break; } writer.WriteString(","); switch (op2) { case PICOperandDataMemoryAddress dstmem: if (PICRegisters.TryGetRegister(dstmem.DataTarget, out var dstreg)) { writer.WriteString($"{dstreg.Name}"); } else { dstmem.Write(writer, options); } break; case PICOperandFSRIndexation dstidx: if (dstidx.Mode != FSRIndexedMode.FSR2INDEXED) { throw new InvalidOperationException($"Invalid FSR2 indexing mode: {dstidx.Mode}."); } writer.WriteString($"[{dstidx.Offset:X2}]"); break; } }
public override void Render(MachineInstructionWriter writer, MachineInstructionWriterOptions options) { writer.WriteOpcode(opcode.ToString()); if (operands.Length > 0) { writer.Tab(); writer.WriteString(operands[0].ToString()); if (operands.Length > 1) { writer.WriteString(","); writer.WriteString(operands[1].ToString()); } } }
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) { int o = Offset != null?Offset.ToUInt16() : 0; string fmt; switch (Mode) { case AddressMode.Accumulator: return; // Implicit, never displayed case AddressMode.Immediate: fmt = "#${0:X2}"; break; case AddressMode.ZeroPage: fmt = "${0:X2}"; break; case AddressMode.ZeroPageX: case AddressMode.ZeroPageY: fmt = "${0:X2},{1}"; break; case AddressMode.Relative: case AddressMode.Absolute: fmt = "${0:X4}"; break; case AddressMode.AbsoluteX: case AddressMode.AbsoluteY: fmt = "${0:X4},{1}"; break; case AddressMode.Indirect: fmt = "(${0:X4})"; break; case AddressMode.IndexedIndirect: fmt = "(${0:X2},{1})"; break; case AddressMode.IndirectIndexed: fmt = "(${0:X2}),{1}"; break; default: throw new NotSupportedException(); } writer.WriteString(string.Format(fmt, o, Register)); }
public override void Render(MachineInstructionWriter writer, MachineInstructionWriterOptions options) { switch (Mnemonic) { case Mnemonic._and: Render3("&", writer, options); return; case Mnemonic._fmul: Render3("*F", writer, options); return; case Mnemonic._mov: RenderOperand(Operands[0], writer, options); writer.Tab(); RenderOperand(Operands[1], writer, options); if (Operands.Length == 2) { return; } writer.WriteString(","); RenderOperand(Operands[2], writer, options); return; } writer.WriteMnemonic(this.Mnemonic.ToString()); RenderOperands(writer, options); }
public override void Render(MachineInstructionWriter writer, MachineInstructionWriterOptions options) { if (Mnemonic == Mnemonic.illegal && Operands.Length > 0 && writer.Platform != null) { var imm = Operands[0] as M68kImmediateOperand; // MacOS uses invalid opcodes to invoke Macintosh Toolbox services. // We may have to generalize the Platform API to allow specifying // the opcode of the invoking instruction, to disambiguate from // "legitimate" TRAP calls. var svc = writer.Platform.FindService((int)imm.Constant.ToUInt32(), null); if (svc != null) { writer.WriteString(svc.Name); return; } } if (dataWidth != null) { writer.WriteOpcode(string.Format("{0}{1}", Mnemonic, DataSizeSuffix(dataWidth))); } else { writer.WriteOpcode(Mnemonic.ToString()); } RenderOperands(writer, options); }
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); }
private void Render3(string infix, MachineInstructionWriter writer, MachineInstructionWriterOptions options) { RenderOperand(Operands[0], writer, options); writer.Tab(); RenderOperand(Operands[1], writer, options); writer.WriteString(infix); RenderOperand(Operands[2], writer, options); }