trap

Raises a software trap or calls a simulator task.

XNZVC –––––
  • Changes no flag

Forms

  • trap

Operands

#imm
A trap number from 0 to 15. #0 to #14 run the handler in vectors 32 to 46; #15 runs the simulator’s task numbered in d0.b. More

trap #0 through trap #14 run handlers installed by the program. trap #15 runs an EASy68K simulator task.

For a software trap, the processor saves the next instruction’s address and the status register on the supervisor stack, enters supervisor mode, and runs the handler from vector 32 + n. The vector entry for trap #n is at $80 + 4 × n. For example, move.l #service, $8C installs service as the handler for trap #3. The handler returns to the next instruction with rte. Without a handler, the program ends at the trap and reports the missing vector. See writing a handler.

For trap #15, the low byte of d0 selects a simulator task. Task 13, for example, prints the null-terminated string at a1. Execution continues after the trap, and the call is available in user mode. The trap task reference lists each task and its registers.

* --- trap #15: one of the simulator's tasks ---
move.b #4, d0
trap #15 ; task 4: read a number into d1

* --- trap #0 to #14: a handler of your own ---
move.l #double, $80 ; trap #0's vector, number 32, is at $80
trap #0 ; runs double, then carries on below

move.b #3, d0
trap #15 ; task 3: print d1, twice the number read
bra END

double:
    add.l d1, d1
    rte ; back to the instruction after the trap

END: