trap
Raises a software trap or calls a simulator task.
- trap #15 and its tasksM68K assembly
- The screen, keyboard and mouse through trapsM68K assembly
- Exceptions and the vector tableM68K assembly
- Interrupts and cyclesM68K assembly
- Print a stringM68K assembly
- Read two numbers and print their sumM68K assembly
- Print a number in any base without helpM68K assembly
- Drawing shapes on the screenM68K assembly
- A bouncing ballM68K assembly
- Move a square with the keyboardM68K assembly
- Changes no flag
Forms
trap
Operands
#imm- A trap number from
0to15.#0to#14run the handler in vectors 32 to 46;#15runs the simulator’s task numbered ind0.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: