# `rte`

[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/rte

**Return from exception** · Privileged

Category: System

Returns from an exception handler by restoring the saved status register and program counter.

Used in: [Exceptions and the vector table](https://asm-editor.specy.app/learn/courses/m68k/talking-to-the-outside-world/exceptions-and-the-vector-table.md) (M68K assembly), [Interrupts and cycles](https://asm-editor.specy.app/learn/courses/m68k/talking-to-the-outside-world/interrupts-and-cycles.md) (M68K assembly)

## Flags

| Flag | Effect |
| --- | --- |
| X | loaded from the stack |
| N | loaded from the stack |
| Z | loaded from the stack |
| V | loaded from the stack |
| C | loaded from the stack |

## Forms

- `rte`

## Description

It restores the whole status register, including S. Returning to user mode therefore makes `a7` the user stack pointer again. `rte` requires supervisor mode and raises a privilege violation in user mode. See [writing a handler](https://asm-editor.specy.app/documentation/m68k/exceptions/handlers.md).

On the 68010 and 68020, the saved frame also contains a format word. `rte` uses it to determine the frame’s size and removes the whole frame. An unsupported format raises a [format error](https://asm-editor.specy.app/documentation/m68k/exceptions/format-error.md).

On the 68020, an interrupt taken while using the master stack leaves a throwaway frame on the interrupt stack. `rte` removes that frame, switches back to the master stack, and then restores the original frame there. See [the throwaway frame](https://asm-editor.specy.app/documentation/m68k/exceptions/throwaway-frame.md).

## Example

```m68k
* --- A handler for a division by zero ---
move.l #div_zero, $14 ; vector 5 is at $14
move.l #100, d0
moveq #0, d1
divu d1, d0 ; d1 is 0, so div_zero runs
move.l d0, d2 ; rte comes back here: d2 = -1
bra END

div_zero:
    moveq #-1, d0 ; an answer the program can test
    rte ; pops the status register and the return address

END:
```
