Exception Handler Installation Example
This program illustrates how to install a handler for the integer divide-by-zero
exception. The integer divide-by-0 exection is
handled through vector 5 in the interrupt vector table. The interrupt
vector table is made up of 256 addresses (vectors).
Each address is a 32 bit number. The location of the address for vector
5 handler is at 0x14 (vector number * 4 = 20).
The program below does the following:
1.) Saves the address of the current divide-by-zero
exception handler. The current handler is installed by the debugger
at reset. This handler
allow the debugger to pop up a box and make you aware of the unhandled
(by your program)
exception.
2.) Places the address of the new divide-by-zero
exception handler in the vector table
3.) Execute an integer divide-by-zero
4.) Restore the address of the original exception handler
in the vector table.
5.) TRAP #15 to exit.
; #########################################################################################
; # Indiana University
; # Computer Science Department
; #
; # Program to illustrate how to setup an exception handler for
divide by zero
; #
; #
; # AUTHOR:
; # Bryce Himebaugh (bhimebau@cs.indiana.edu)
; # IUCS Staff
; # 3/01/01
; #
; #########################################################################################
SECTION code
START:
; new divide-by-0 interrupt handler installation
move.l #0x14,a0
; address in vector table for div by 0 handler
move.l (a0),-(sp)
; save the current divide by zero handler address
move.l #div_0_handler,(a0)
; place the address of div_0_handler into vector table
; if you comment out the above line, the debugger's
; trap handler will execute on the divide by zero.
; Divide by 0 operation
clr.w d0
; clear lower word of d0
divu.w d0,d1
; perform divide by 0 (don't care about d1 value)
; Restoration of original divide-by-0 handler
move.l (sp)+,(a0)
; save the current divide by zero handler address
; Exit program
clr.b d1
; setup trap #15 for exit
TRAP #15
; exit program
div_0_handler:
movem.l d0-d2/a0-a2,-(sp)
; save any regs that you plan to use
;### Handler stuff goes here ###
movem.l (sp)+,d0-d2/a0-a2
; restore the saved regs.
rte
; return from exception
|