# `trapv`

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

**Trap on overflow**

Category: System

Raises an overflow exception through vector 7 at $1C if V is set, and continues normally otherwise.

## Flags

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

Reads: V

## Forms

- `trapv`

## Description

Place it after arithmetic to handle an overflow with an exception handler. The handler’s `rte` returns to the instruction after `trapv`. Without a handler, an overflow ends the program there. See [writing a handler](https://asm-editor.specy.app/documentation/m68k/exceptions/handlers.md).

## Example

```m68k
* --- Send an overflow to a handler ---
move.l #overflow, $1C ; vector 7 is at $1C
move.b #100, d0
add.b #100, d0 ; 200 does not fit a signed byte: V is set
trapv ; V is set, so overflow runs
move.b d0, d1 ; rte comes back here: d1 = 127
bra END

overflow:
    move.b #127, d0 ; the largest signed byte instead
    rte

END:
```
