Arithmetic Exceptions

VAX11

 

Arithmetic Exceptions

 

This section describes exceptions occurring as the result of an arithmetic or conversion operation. These mutually exclusive exceptions all are assigned to the same vector in the System Control Block. Each of them indicates that an exception occurred during the last instruction and that the instruction has been completed (in the case of a trap) or backed up (fault). A code unique to each exception type is then pushed on the stack as longword.

 

Trap code

Exception type

1

Integer overflow

2

Integer divide by zero

7

Subscript range

 

 

Integer Overflow Trap

 

An integer overflow trap is an exception indicating that the last instruction executed had an integer overflow which set the V condition code.

The trap only occurs if the integer overflow enable bit (IV) in the PSW is set. The result stored is the low order part of the correct result, and the type code pushed on the stack is a 1. Not that the instructions RET, REI, REMQUE, MOVTUC and BISPSW, do not cause overflow even if they set V.

 

 

Integer Divide By Zero Trap

 

An integer divide by zero trap is an exception indicating that the last instruction executed had an integer zero divisor. The result stored is equal to the dividend, and the condition code V is set. The type code pushed on the stack is 2.

 

 

Example:

 

.text

 

.set ZERO_FAULT,              0x34

 

main: .word 0

 

      calls $0, InitZeroHandler

      movb $4, r0

      divl2 $0, r0

 

      calls $0, ClearZeroHandler

      movb $4, r0

      divl2 $0, r0

 

      pushl $0

      calls $1, .exit

 

InitZeroHandler: .word 2

      mfpr SCBB, r1

      moval handlezero, ZERO_FAULT(r1)

      ret

 

ClearZeroHandler: .word 2

      mfpr SCBB, r1

      movl $0, ZERO_FAULT(r1)

      ret

 

handlezero:

      pushl 0(sp)

      pushal format

      calls $2, .printf

      rei

 

.data

format: .asciz "Divide by Zero Handler. Return Address: 0x%X\n"

 

Subscript Range Trap

 

A subscript range trap is an exception indicating that the last instruction was an INDEX instruction with the subscript operand is lower than the low operand or greater than the high operand. The result is stored in the indexout, and the condition codes are set as if the subscript were within range. The type code pushed on the stack is 7.