trapv
Trap on overflow
Raises an overflow exception through vector 7 at $1C if V is set, and continues normally otherwise.
XNZVC –––––
- Leaves every flag unchanged
- Reads V
Forms
trapv
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.
* --- 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: