@macro op_mov_reg(d, s)
  void {class}::op_mov_{d}_{s}() {
    op_io();
    regs.{d} = regs.{s};
    regs.p.n = (regs.{d} & 0x80);
    regs.p.z = (regs.{d} == 0);
  }
@endmacro

@macro op_mov_sp_x()
  void {class}::op_mov_sp_x() {
    op_io();
    regs.sp = regs.x;
  }
@endmacro

@macro op_mov_reg_const(r)
  void {class}::op_mov_{r}_const() {
    regs.{r} = op_readpc();
    regs.p.n = (regs.{r} & 0x80);
    regs.p.z = (regs.{r} == 0);
  }
@endmacro

@macro op_mov_a_ix()
  void {class}::op_mov_a_ix() {
    op_io();
    regs.a = op_readdp(regs.x);
    regs.p.n = (regs.a & 0x80);
    regs.p.z = (regs.a == 0);
  }
@endmacro

@macro op_mov_a_ixinc()
  void {class}::op_mov_a_ixinc() {
    op_io();
    regs.a = op_readdp(regs.x++);
    op_io();
    regs.p.n = (regs.a & 0x80);
    regs.p.z = (regs.a == 0);
  }
@endmacro

@macro op_mov_reg_dp(r)
  void {class}::op_mov_{r}_dp() {
    sp = op_readpc();
    regs.{r} = op_readdp(sp);
    regs.p.n = (regs.{r} & 0x80);
    regs.p.z = (regs.{r} == 0);
  }
@endmacro

@macro op_mov_reg_dpi(r, i)
  void {class}::op_mov_{r}_dp{i}() {
    sp = op_readpc();
    op_io();
    regs.{r} = op_readdp(sp + regs.{i});
    regs.p.n = (regs.{r} & 0x80);
    regs.p.z = (regs.{r} == 0);
  }
@endmacro

@macro op_mov_reg_addr(r)
  void {class}::op_mov_{r}_addr() {
    sp  = op_readpc() << 0;
    sp |= op_readpc() << 8;
    regs.{r} = op_readaddr(sp);
    regs.p.n = (regs.{r} & 0x80);
    regs.p.z = (regs.{r} == 0);
  }
@endmacro

@macro op_mov_a_addri(i)
  void {class}::op_mov_a_addr{i}() {
    sp  = op_readpc() << 0;
    sp |= op_readpc() << 8;
    op_io();
    regs.a = op_readaddr(sp + regs.{i});
    regs.p.n = (regs.a & 0x80);
    regs.p.z = (regs.a == 0);
  }
@endmacro

@macro op_mov_a_idpx()
  void {class}::op_mov_a_idpx() {
    dp  = op_readpc() + regs.x;
    op_io();
    sp  = op_readdp(dp + 0) << 0;
    sp |= op_readdp(dp + 1) << 8;
    regs.a = op_readaddr(sp);
    regs.p.n = (regs.a & 0x80);
    regs.p.z = (regs.a == 0);
  }
@endmacro

@macro op_mov_a_idpy()
  void {class}::op_mov_a_idpy() {
    dp  = op_readpc();
    op_io();
    sp  = op_readdp(dp + 0) << 0;
    sp |= op_readdp(dp + 1) << 8;
    regs.a = op_readaddr(sp + regs.y);
    regs.p.n = (regs.a & 0x80);
    regs.p.z = (regs.a == 0);
  }
@endmacro

@macro op_mov_dp_dp()
  void {class}::op_mov_dp_dp() {
    sp = op_readpc();
    rd = op_readdp(sp);
    dp = op_readpc();
    op_writedp(dp, rd);
  }
@endmacro

@macro op_mov_dp_const()
  void {class}::op_mov_dp_const() {
    rd = op_readpc();
    dp = op_readpc();
    op_readdp(dp);
    op_writedp(dp, rd);
  }
@endmacro

@macro op_mov_ix_a()
  void {class}::op_mov_ix_a() {
    op_io();
    op_readdp(regs.x);
    op_writedp(regs.x, regs.a);
  }
@endmacro

@macro op_mov_ixinc_a()
  void {class}::op_mov_ixinc_a() {
    op_io();
    op_io();
    op_writedp(regs.x++, regs.a);
  }
@endmacro

@macro op_mov_dp_reg(r)
  void {class}::op_mov_dp_{r}() {
    dp = op_readpc();
    op_readdp(dp);
    op_writedp(dp, regs.{r});
  }
@endmacro

@macro op_mov_dpi_reg(r, i)
  void {class}::op_mov_dp{i}_{r}() {
    dp  = op_readpc();
    op_io();
    dp += regs.{i};
    op_readdp(dp);
    op_writedp(dp, regs.{r});
  }
@endmacro

@macro op_mov_addr_reg(r)
  void {class}::op_mov_addr_{r}() {
    dp  = op_readpc() << 0;
    dp |= op_readpc() << 8;
    op_readaddr(dp);
    op_writeaddr(dp, regs.{r});
  }
@endmacro

@macro op_mov_addri_a(i)
  void {class}::op_mov_addr{i}_a() {
    dp  = op_readpc() << 0;
    dp |= op_readpc() << 8;
    op_io();
    dp += regs.{i};
    op_readaddr(dp);
    op_writeaddr(dp, regs.a);
  }
@endmacro

@macro op_mov_idpx_a()
  void {class}::op_mov_idpx_a() {
    sp  = op_readpc();
    op_io();
    sp += regs.x;
    dp  = op_readdp(sp + 0) << 0;
    dp |= op_readdp(sp + 1) << 8;
    op_readaddr(dp);
    op_writeaddr(dp, regs.a);
  }
@endmacro

@macro op_mov_idpy_a()
  void {class}::op_mov_idpy_a() {
    sp  = op_readpc();
    dp  = op_readdp(sp + 0) << 0;
    dp |= op_readdp(sp + 1) << 8;
    op_io();
    dp += regs.y;
    op_readaddr(dp);
    op_writeaddr(dp, regs.a);
  }
@endmacro

@macro op_movw_ya_dp()
  void {class}::op_movw_ya_dp() {
    sp = op_readpc();
    regs.a = op_readdp(sp + 0);
    op_io();
    regs.y = op_readdp(sp + 1);
    regs.p.n = (regs.ya & 0x8000);
    regs.p.z = (regs.ya == 0);
  }
@endmacro

@macro op_movw_dp_ya()
  void {class}::op_movw_dp_ya() {
    dp = op_readpc();
    op_readdp(dp);
    op_writedp(dp + 0, regs.a);
    op_writedp(dp + 1, regs.y);
  }
@endmacro

@macro op_mov1_c_bit()
  void {class}::op_mov1_c_bit() {
    sp  = op_readpc() << 0;
    sp |= op_readpc() << 8;
    bit = sp >> 13;
    sp &= 0x1fff;
    rd = op_readaddr(sp);
    regs.p.c = (rd & (1 << bit));
  }
@endmacro

@macro op_mov1_bit_c()
  void {class}::op_mov1_bit_c() {
    dp  = op_readpc() << 0;
    dp |= op_readpc() << 8;
    bit = dp >> 13;
    dp &= 0x1fff;
    rd = op_readaddr(dp);
    (regs.p.c) ? rd |= (1 << bit) : rd &= ~(1 << bit);
    op_io();
    op_writeaddr(dp, rd);
  }
@endmacro

