internal void Sub(ParsedOperand opSrc, ParsedOperand opDst) { EmitDoubleOperandInstruction(0xE000, opSrc, opDst); }
public void Dec(ParsedOperand op) { EmitSingleOperandInstruction(0x0AC0, op); }
public void Movb(ParsedOperand opSrc, ParsedOperand opDst) { EmitDoubleOperandInstruction(0x9000, opSrc, opDst); }
internal void Asr(ParsedOperand op) { EmitSingleOperandInstruction(0x0C80, op); }
internal void Clrb(ParsedOperand op) { EmitSingleOperandInstruction(0x8A00, op); }
internal void Jsr(ParsedOperand[] ops) { if (ops.Length != 2) throw new ArgumentException("ops"); if (ops[0].Type != AddressMode.Register) throw new ArgumentException("First argument must be a register."); Debug.Print("ops(0): {0} {1}", ops[0].Register.Name, ops[0].Register.Number); EmitSingleOperandInstruction(0x0800 | (ops[0].Register.Number << 6), ops[1]); }
private int EncodeOperandField(ParsedOperand op) { var enc = 0; switch (op.Type) { case AddressMode.Register: enc = op.Register.Number; break; case AddressMode.RegDef: enc = 0x08 | op.Register.Number; break; case AddressMode.AutoIncr: enc = 0x10 | op.Register.Number; break; case AddressMode.AutoDecr: enc = 0x20 | op.Register.Number; break; case AddressMode.Immediate: enc = 0x17; break; case AddressMode.Absolute: enc = 0x1F; break; default: throw new NotImplementedException("type " + op.Type); } return enc; }
private void EmitOperand(ParsedOperand op) { switch (op.Type) { case AddressMode.Register: case AddressMode.AutoIncr: case AddressMode.AutoDecr: case AddressMode.RegDef: break; case AddressMode.Immediate: emitter.EmitLeUInt16((int) BaseAddress.ToLinear() + op.Offset); if (op.Symbol != null) { ReferToSymbol(op.Symbol, emitter.Length - 2, PrimitiveType.Word16); } break; case AddressMode.Absolute: emitter.EmitLeUInt16((int) BaseAddress.ToLinear()); if (op.Symbol != null) { ReferToSymbol(op.Symbol, emitter.Length - 2, PrimitiveType.Word16); } break; default: throw new NotImplementedException(); } }
private void EmitSingleOperandInstruction(int opcode, ParsedOperand op) { opcode = opcode | EncodeOperandField(op); emitter.EmitLeUInt16(opcode); EmitOperand(op); }
private void EmitDoubleOperandInstruction(int opcode, ParsedOperand opSrc, ParsedOperand opDst) { opcode = opcode | (EncodeOperandField(opSrc) << 6) | EncodeOperandField(opDst); emitter.EmitLeUInt16(opcode); EmitOperand(opSrc); EmitOperand(opDst); }