# `movec`

[M68K Documentation](https://asm-editor.specy.app/documentation/m68k.md) › [Instructions](https://asm-editor.specy.app/documentation/m68k/instruction.md)

Web page: https://asm-editor.specy.app/documentation/m68k/instruction/movec

**Move control register** · Privileged · 68010

Category: System

Copies a control register to a data or address register, or copies a data or address register to a control register.

Size .l · 68010 and 68020 only: select `opt p=68010` before any code or data

## Flags

| Flag | Effect |
| --- | --- |
| X | not changed |
| N | not changed |
| Z | not changed |
| V | not changed |
| C | not changed |

## Forms

- `movec Rc, Rn`
  - Source: usp, Rc
  - Destination: Dn, An
- `movec Rn, Rc`
  - Source: Dn, An
  - Destination: usp, Rc

## Operands

- [`Rc`](https://asm-editor.specy.app/documentation/m68k/addressing-mode/control-registers.md): A control register: on the 68010 `vbr`, the vector base register, where the vector table starts; `sfc` or `dfc`, the source or destination function code; or `usp`, the user stack pointer. The 68020 adds `msp` and `isp`, its master and interrupt stack pointers, and `cacr` and `caar`, its cache registers.
- [`Rn`](https://asm-editor.specy.app/documentation/m68k/addressing-mode/direct.md): A data or address register, `d0` to `d7` or `a0` to `a7`.

## Description

On the 68010, it accesses `vbr` (vector base), `sfc` and `dfc` (function codes), and `usp` (user stack pointer). After `movec d0, vbr`, exception vectors are read from VBR + 4 × the vector number. See [the 68010 vector table](https://asm-editor.specy.app/documentation/m68k/exceptions/68010.md). The transfer is always long, preserves the flags and requires supervisor mode.

The 68020 adds `msp` and `isp`, the master and interrupt stack pointers. In supervisor mode, the M bit of `sr` selects which one is `a7`. Initialize `msp` with `movec` before setting M. It starts at zero. See [master and interrupt stacks](https://asm-editor.specy.app/documentation/m68k/exceptions/master-stack.md).

The 68020 also adds `cacr` and `caar`, the cache control and cache address registers. The editor does not simulate a cache. `cacr` retains only bits 0 and 1 of a written value. `caar` retains all 32 bits.

## Example

```m68k
opt p=68010
* --- Move the vector table to $8000 ---
move.l #div_zero, $8000+5*4 ; vector 5 of the new table
move.l #$8000, d0
movec d0, vbr ; from now on, vectors are read at $8000
moveq #0, d1
divu d1, d0 ; division by zero: the handler at $8014 runs
movec vbr, d2 ; read it back: d2 = $8000
bra END

div_zero:
    moveq #-1, d0
    rte

END:
```
